jquery HOWTO select a node and clone it ,then remove a button finally insert into another node
below is part of html code
<div id="test1"><span><input type='text' name='add'/><input type='text' name='del'/><span></div>
<div id="container"></div>
i tried to use jquery to clone #test1 node and remove the add button then add the result to #container i tried write the code like belows,but it seems didn't work
$("#test1").clone().remove("input[name='add']").appendTo("#container")
开发者_如何学编程
hope someone could help,i have re-edited the question
How about this?
var t1 = $("#test1").clone();
$("input[name='add']", t1).remove();
$(t1).appendTo("#container");
$(':button').remove();
or $('input[type="button"]').remove()
will probably do what you're looking for.
One way is to use replace
function:
var str = html.replace("<input type='text' name='add'/>", "");
Result:
<div><span><input type='text' name='del'/>
If you have more than one of those instances, you can use regex with /g
modifier:
var str = html.replace(/<input type='text' name='add'\/>/g, "");
Result:
<div><span><input type='text' name='del'/>
精彩评论