Rebecca O'Sullivan Rebecca O'Sullivan - 3 months ago 6
HTML Question

How to remove all the elements with null id

I want to check for ANY element on the page where the id has no value, and then remove them using jQuery's

remove()
.

This is how the id's look when they have no value passed from the CMS:

<iframe id class="iframeCol"...></iframe>
<div id class="sectional">..</div>


How do I target any and all elements where the id is as above?

Answer

You can use the attribute selector to achieve this:

$('[id=""]').remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<iframe id class="iframeCol">Remove this</iframe>
<div id class="sectional">And remove this</div>

<div>Keep this</div>
<div id="foo">And this</div>