0

I know I shouldn't be using "onclick" with jQuery. The reason I am using it anyway is that there is pre-existing code where a button has an onclick attribute that opens a pop-up window. I'm creating a new button inside of a jquery dialog that needs to open the same target. It's just easier (I think?) to copy the original button's onclick attribute rather than trying to get the URL out of it and using a better handler.

$insert = $(data).find('.button.compare:first'); // find the button in $(data). This already works.
$("#dialog").html('<button type="button" title="View List" class="button compare" onclick="' + $insert.clone().prop('onclick') + '")><span>View List</span></button>'); // get the onclick property - seems to work but button does nothing

$insert is a copy of the button. I actually insert that copy later in the page and it works fine there. But the new button I create inside the jQuery-ui dialog does not work. It doesn't open a new window.

EDIT: I just noticed that there is a difference between the original onclick attribute and the copied one. The original looks something like:

`onclick="popwin(....)"

And the copy adds some stuff to look like:

onclick="function onclick(event) { popwin(...)"

Why is this?

Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120

1 Answers1

0

I managed to solve this myself by changing

$insert.clone().prop('onclick') 

to

$insert.clone().attr('onclick')

Though I'm not sure why there is a difference here.

Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120