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();
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();
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();
if(typeof $("#foo").attr('data-type') == 'undefined')
{
$("#foo").removeAttr('data-type');
}
If you dont care about the value you can just do
$('#foo[data-type]').remove();