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

WBOY
Release: 2016-06-24 11:58:10
Original
3107 people have browsed it

For example

<div>  <vbox name="xxx" />  <vbox />  <vbox /></div>
Copy after login


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>
Copy after login

Use xpath

//vbox[not(@name)]
Copy after login
Copy after login
Copy after login
Copy after login

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

$('vbox:not([name])')
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

It is recommended that you use the universal jquery

$('vbox:not([name])')
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

It is recommended that you use the universal jquery



1.

Use xpath

//vbox[not(@name)]
Copy after login
Copy after login
Copy after login
Copy after login

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



Sorry, add
to use CSS selector


use xpath

//vbox[not(@name)]
Copy after login
Copy after login
Copy after login
Copy after login

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



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)]
Copy after login
Copy after login
Copy after login
Copy after login

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



Sorry, add
to use CSS selector

not

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!