简体   繁体   中英

Selecting the First Appearing Child Within the First Element On a Page with JQuery?

I want to use the gt() selector within a .load() method. Can this be accomplished?

At the moment, I am seeking a solution which would allow me to apply a .children(':gt(0)') selector after .entry:first is called.

Here is my progress, so far:

$("#embed-content").load("https://URL.com/page/ .entry:first .children(':gt(0)')", function(data) {});

Note, the first element from the load source will not always be a div , and will not always contain the same id or class, these aspects will vary.

.entry:first .children(':gt(0)') would be .entry:first > :gt(0) . The > is the direct child combinator, and then of course :gt(0) is "greater than index 0".

I don't think that's what you want though. In a comment you've said:

I am trying to select the first child element within the first .entry div from the loaded page source.

:gt(0) will skip the first such element, rather than selecting it. To select it you want: .entry:first > :first :

 $(".entry:first > :first").css({ color: "green", fontWeight: "bold" }); 
 <div class="entry"> <span>first child of first .entry</span> <span>second child of first .entry</span> </div> <div class="entry"> <span>first child of second .entry</span> <span>second child of second .entry</span> </div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM