I need to remove a tags with specific attribute value from a div tag.
This is for example:
<div id='testdiv'>
<a dir='hello' href='#' ></a>
<a dir='how' href='#' ></a>
<a dir='which' href='#' ></a>
</div>
<input type='button' id='btn' />
Here is my jQuery:
$('#btn').click(function(){
if($("#testdiv").find("a[dir='hello']").length == 1)
{
$("#testdiv").remove("a[dir=hello]");
}
}
But its not working. What change shall I need to do with my jQuery?
dirisn't a valid attribute for an anchor. If you need to use custom attributes, check outhtml5 data attributes