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

How to select elements whose attributes are not equal to a certain value or do not have the attribute_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:58:103108browse

For example

<div>  <vbox name="xxx" />  <vbox />  <vbox /></div>


How to select two vboxes without name attribute


Reply to discussion (solution)

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)]

Use jQuery
$('vbox:not([name])')

$('vbox:not([name])')

It is recommended that you use the universal jquery

$('vbox:not([name])')

It is recommended that you use the universal jquery



1.

Use xpath

//vbox[not(@name)]

Use jQuery
$('vbox:not([name])')



Sorry, add
to use CSS selector


use xpath

//vbox[not(@name)]

Use jQuery
$('vbox:not([name])')



Sorry, add
You need to use CSS selector

Try it
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)]

Use jQuery
$('vbox:not([name])')



Sorry, add
to use CSS selector

not

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:cursor mouse style?Next article:cursor mouse style?