Home > Article > Web Front-end > How to select elements whose attributes are not equal to a certain value or do not have the attribute_html/css_WEB-ITnose
For example
<div> <vbox name="xxx" /> <vbox /> <vbox /></div>
Although it can be taken out in this way, the lower version of IE does not seem to support this kind of tag. Use with caution.
<div id="div"> <vbox name="xxx" ></vbox> <vbox></vbox> <vbox></vbox></div><script type="text/javascript"> var div = document.getElementById('div'); var box = div.getElementsByTagName('vbox'); var arr = []; for(var i = 0; i < box.length; i++){ if(!box[i].getAttribute('name')){ arr.push(box[i]); } } console.log(arr);</script>
Use xpath
//vbox[not(@name)]
$('vbox:not([name])')
$('vbox:not([name])')
$('vbox:not([name])')
Use xpath
//vbox[not(@name)]
$('vbox:not([name])')
use xpath
//vbox[not(@name)]
$('vbox:not([name])')
The following jQuery is a CSS selector. If you use jQuery, you should be able to take out the elements you need. I have tested it before replying yesterday. You can click to view the demo code
If you use other js frameworks, you can tell me.
Use xpath
//vbox[not(@name)]
$('vbox:not([name])')
not