Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard CSS selector similar to :eq() in jQuery?

Tags:

I don't know if there is a CSS selector can do the same as the line below (jQuery code):

.tab_cadre_central .top:eq(0) table tbody tr td table tbody tr:eq(3) 

I have tried in CSS something like this:

.tab_cadre_central .top::nth-child(0) table tbody tr td table tbody nth-child:eq(3) {     display:none; } 

but it didn't work.

like image 399
user2077308 Avatar asked Feb 22 '13 02:02

user2077308


People also ask

Can I use CSS selectors in jQuery?

The most basic concept of jQuery is to "select some elements and do something with them." jQuery supports most CSS3 selectors, as well as some non-standard selectors.

What is eq method in jQuery?

jQuery eq() Method The eq() method returns an element with a specific index number of the selected elements. The index numbers start at 0, so the first element will have the index number 0 (not 1).

What is TD eq in jQuery?

TD #7. TD #8. Apply three different styles to list items to demonstrate that :eq() is designed to select a single element while :nth-child() or :eq() within a looping construct such as . each() can select multiple elements.

What is the use of EQ selector in HTML?

The :eq () selector selects an element with a specific index number. The index numbers start at 0, so the first element will have the index number 0 (not 1). This is mostly used together with another selector to select a specifically indexed element in a group (like in the example above).

Should I look for jQuery alternatives?

Say you don’t need all the methods that are in jQuery API and you would need only a few among them, you could look for alternatives. jQuery is around 250Kb. Maybe if you are looking for a smaller file that does all your needs, you would want to look for jQuery Alternatives. Below is the Different jQuery Alternatives which are as follows: 1.

Do you need to know CSS to be a full stack developer?

But I think if you’re going to call yourself a full-stack developer, you should know the basics of CSS. And the basics start with the selector. Disclaimer: jQuery selectors aren’t actually unique to jQuery — they’re actually CSS selectors.

How do I select all elements on a page using CSS?

For example, you can select all div s on your page by using the simple selector div. Hey, that was easy! The second way is probably the one you’ll use the most: the class attribute. You can select by class by using a dot (.) , so in the example above, to select the all elements with class section I use .section as a selector.


1 Answers

While jQuery's :eq() uses 0-based indexing, :nth-child() uses 1-based indexing, so you need to increment your indexes appropriately:

.tab_cadre_central .top:nth-child(1) table tbody tr td table tbody tr:nth-child(4) 

But you should really think about refactoring that selector...


⚠ It's worth noting that although :eq() and :nth-child() can behave similarly - they are certainly not the same. :eq() will select the n+1 th element in the set while :nth-child() will select all elements in the set that are the n th child of their respective parents. ⚠

<div>     <span></span>     <span></span> </div> <div>     <span></span> </div> 

The selector div span:nth-child(1) will fetch two elements, while div span:eq(0) will only select one.

like image 132
Dennis Avatar answered Nov 01 '22 14:11

Dennis