Reputation: 287
How can I check if a div has a data-attribute and remove the div if it has that data-attribute, the opposite works like this:
$("div[id='foo']").not('[data-type=edit]').remove();
Upvotes: 2
Views: 6540
Reputation: 337743
Remove the not()
and use the attribute in the main selector:
$('#foo[data-type=edit]').remove();
If you only want to find the element that has the data-type
attribute, regardless of its value, you can use this:
$('#foo[data-type]').remove();
Upvotes: 5
Reputation: 2468
If you dont care about the value you can just do
$('#foo[data-type]').remove();
Upvotes: 0
Reputation: 4674
if(typeof $("#foo").attr('data-type') == 'undefined')
{
$("#foo").removeAttr('data-type');
}
Upvotes: 1