Reputation: 27445
how to add onclick='openLightB('remove_ddi',500);'
in to <a>open</a>
with jquery function
my present code is like this
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a").replaceWith("<a onclick='openLightB('remove_ddi',500);'>Remove</a>");
});
unfortunately result coming like this
<a remove_ddi',500);'="" onclick="openLightB(">Remove</a>
Upvotes: 4
Views: 13308
Reputation: 33
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a").attr('onClick', 'openLightB("remove_ddi",500);'); });
Upvotes: -1
Reputation: 393
This work for quotes problems:
$(document).ready(function(){
$(".remove_row").click( function(){
$(".ddi tr:eq(2) td:eq(5) a").replaceWith("<a onclick=\"openLightB('remove_ddi',500);\">Remove</a>");
});
});
Upvotes: 3
Reputation: 18568
try this
<a href="javascript:openLightB('remove_ddi',500)">Remove</a>
jquery
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a").prop('href','javascript:openLightB("remove_ddi",500);');
});
Upvotes: -1
Reputation: 79830
You can fix your code by changing it as below,
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a")
.replaceWith("<a onclick=\'openLightB(\'remove_ddi\',500);\'>Remove</a>");
});
or simplify it,
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a").click (function () {
$(this).text('Remove');
openLightB('remove_ddi',500);
});
});
Also if you are using jQuery 1.7, then use .on
//replace <.remove_row container> with .remove_row container
$('<.remove_row container>').on("click", '.remove_row', function(){
$(".ddi tr:eq(2) td:eq(5) a").click (function () {
$(this).text('Remove');
openLightB('remove_ddi',500);
});
});
Upvotes: 5
Reputation: 30666
How about letting jquery deal with escaping the quotes by using .attr():
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a").attr('onclick', "openLightB('remove_ddi',500);");
});
BTW, .live() is deprecated and could be removed from the library any time in the future. You should consider using .delegate() or .on() for event delegation.
Upvotes: 9
Reputation: 50288
$(".remove_row").live("click", function(){
$(".ddi tr:eq(2) td:eq(5) a").attr('onclick', 'openLightB("remove_ddi",500);');
});
Upvotes: 1