Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get the attribute of the nth child with jQuery?
    text
    copied!<p>I have my html code like:</p> <pre class="lang-html prettyprint-override"><code>&lt;ul id="abc"&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/laxmi-bank.html"&gt;Laxmi Bank&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/nepal-development-bank.html"&gt;Nepal Development Bank&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/clean-energy-development- bank.html"&gt;Clean Energy Development Bank&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/gorkha-development-bank.html"&gt;Gorkha Development Bank&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/bank-of-kathmandu.html"&gt;Bank of Kathmandu&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/nic-bank.html"&gt;NIC Bank&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/bank-of-asia-nepal-limited.html"&gt;Bank of Asia Nepal Limited&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://koolfinance.blogspot.com/2011/06/nepal-sbi-bank-ltd.html"&gt;Nepal SBI Bank Ltd.&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I need to find the <code>href</code> value or a tag's target page of <strong>specific index</strong>. E.g.: if the index is 1, it should return: <code>http://koolfinance.blogspot.com/2011/06/nepal-development-bank.html</code> I tried: </p> <pre class="lang-js prettyprint-override"><code>$targetLink = $('#abc a:nth-child(' + myIndex + ')').attr('href'); </code></pre> <p>but its returning <strong>undefined.</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload