How can I get and save this value

3

I have a program too big for here and so I created a fiddle to illustrate my problem.

I want to catch and save a p , but alert is always empty. Can you help me out?

HTML

<ul>
    <li>1</li>
    <li>2</li>
    <li class = "middle_item">
        <a>
            <div id= "box">
                <div id= "header">
                    <p>1234567</p>
                </div>
            </div>
            <div></div>
            <div></div>

        </a>           
    </li>
    <li>4</li>
    <li>5</li>
</ul>

JavaScript

var aqui = $("li .middle_item .header").text();
alert(aqui);

FIDDLE

    
asked by anonymous 21.05.2015 / 18:21

1 answer

2

You should note that:

  • li .middle_item is the ID selector, you should then change the class selector li to middle_item .

Also note that since IDs are unique then the # part is redundant.

It should then be:

var aqui = $("#header p").text();

jsFiddle: link

    
21.05.2015 / 18:24