• DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        refer to first link of particular div

        6.4k Views Asked by Jamol At 07 August 2012 at 08:03 2025-12-21T01:44:04.977722

        I have following elements:

        <div class="content" id="content_1" style="display: none; ">
        
        <ul class="ad-thumb-list" style="width: 473px; ">
        
        <li> 
        <a href="../images/portfolio/portfolio_1_1.png" class="ad-thumb0 ad-active">
        <img src="../images/portfolio/thumbs/thumb_1_1.png"  style="opacity: 1; ">
        </a>
        </li>
        
            <li> 
        <a href="../images/portfolio/portfolio_1_2.png" class="ad-thumb0">
        <img src="../images/portfolio/thumbs/thumb_1_1.png"  style="opacity: 1; ">
        </a>
        </li>
        
          <li> 
        <a href="../images/portfolio/portfolio_1_3.png" class="ad-thumb0">
        <img src="../images/portfolio/thumbs/thumb_1_1.png"  style="opacity: 1; ">
        </a>
          </li>         
        
         </ul>
        
        </div>
        

        I need to get href attribute of first link <a> inside <ul> <li>

        I have several this kind of divs, as you can see it has id='content_1', so others will have id='content_2'... and so on.

        How can I get href of first a in first li of a called div with jQuery?

        jquery attributes refer
        Original Q&A
        2

        There are 2 best solutions below

        1
        Arsen K. Arsen K. On 07 August 2012 at 08:55 BEST ANSWER
        $('#content_1 li:first a').attr('href');
        

        if you have many divs, then:

        $('.content').each( function() {
            $(this).find('li:first a').attr('href');
        });
        
        2
        Chris Chris On 07 August 2012 at 08:12

        The XPath to the a of interest would be:

        //div[@id="content_1"]/ul/li[1]/a
        

        Which means, anywhere below the root of the document find a div with the specified id. Under that, find a ul and get its first li. Inside that, there is an a.

        How you actually achieve that in your case depends on what you're working with (client-side JS? one of the frameworks? web-scraping script?).

        Related Questions in JQUERY

        • How to sort these using Javascript or Jquery Most effectively
        • Ajax jQuery firing multiple time display event for the same result
        • .hover() seems to overwrite .click()
        • Check for numeric value with optional commas javascript
        • Extending Highmaps Side Effect
        • Array appending after each onclick and loop in javascript
        • how can i append part of a table based on how many tr it has?
        • Play multiple audio files in a slider
        • Remove added set of rows
        • Access property of an object of type [Model] in JQuery
        • AJAX PHP - Reload div after submit
        • proengsoft/laravel-jsvalidation ReferenceError: jQuery is not defined
        • when a checkbox is checked how to display a different hidden element using javascript
        • Get jquery error Uncaught RangeError: Maximum call stack size exceeded
        • Removing only the closest thead on table filtering

        Related Questions in ATTRIBUTES

        • Ajax-update only a component attribute, not the whole component nor its children
        • How to move an attribute and its value from one element to another
        • Rails WiceGrid with multiples attributes in the same column
        • Java Running A Constructor from a Subclass
        • Is it possible to implement a conditional attribute on a field in Odoo?
        • Swapping attributes in AD
        • Visual Studio: replace default doubleclick-event
        • Accessing a custom attribute from within an instanced object
        • How to mark function argument as output
        • jQuery link elements by attribute
        • Render outcome of "action" attribute?
        • Entity Framework Code First from database not adding Key attribute
        • Java Atribute In Class and Subclass
        • Applying product attributes
        • Leverage MultipleApiVersions in Swagger with attribute versioning

        Related Questions in REFER

        • Redirect based on referrer URL
        • Python: find pattern and replace word by referring to another line
        • How to refer from a column to names of other columns and create a new column
        • What decides when the git reference-transaction hook runs?
        • AS3: How to refer an object by his properties
        • is there any method or api available to create unique referral link for telegram bot with python
        • Why cannot refer to the embed namespace in c++
        • Writing my own api, help please
        • refer to first link of particular div
        • Analyzing tree/structure of XML (tags referencing eachother)
        • Reference to java primitive types for casting
        • CodeIgniter - Refer Url - Saved In Database
        • How can I hide from SimilarWeb websites that refer to my websites?
        • Java: How to refer to a class inside the class but of another element?
        • How to set that the referer is the PayPal?

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates