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();
data-type is present or not. That means data-type might have any value. Your code only works only if data-type=edit .$("div[id='foo']").id, which you really, really shouldn't. To answer your question though, you can use multiple attribute selectors like this: $('div[id="foo"][data-type]')$("div#foo[data-type]")this .