msm.oliveira
msm.oliveira

Reputation: 211

How can i get that value

I have a program, but it's too big to spam it here, so I made a fiddle to illustrate my problem.

I need to catch and store in a variable the number 6, but alert gives me undefined or [object]. Can you help me please?

HTML

<ul>
    <li>1</li>
    <li>2</li>
    <li class = "middle_item">
        <a>3</a>
        <a>6</a>
        <a>7</a>
    </li>
    <li>4</li>
    <li>5</li>
</ul>

JavaScript

var aqui = $("li.middle_item").get("a:nth(2)"); 
alert(aqui);

Fiddle here

Upvotes: 1

Views: 31

Answers (2)

Hoyen
Hoyen

Reputation: 2519

Try:

var aqui = $("li.middle_item").find("a:nth(2)").text();

Upvotes: 0

lshettyl
lshettyl

Reputation: 8181

Use .text and :eq as below.

var aqui = $("li.middle_item a:eq(1)").text();
alert(aqui); // = 6

Demo@Fiddle

Upvotes: 3

Related Questions