wala rawashdeh
wala rawashdeh

Reputation: 433

.innerHTML is not defined

I have the following HTML code

<div class="main-nav" id="main-content">
        <ul class="main-nav-c">
            <li id="Li1"><a id="A1" disabled="disabled" class="sprites"><span
                class="headerV">Value 1</span></a></li>
            <li id="Li2"><a id="A2" class="sprites" >
                <span class="empx9b12">Value 2</span></a></li>
        </ul>
</div>

and to get the innerHtml of the first li I use the following jquery

   value = $('#main-content .main-nav-c li').eq(0).find('a').find('.headerV')[0].innerHTML.trim().toUpperCase();

but I got the following error: $(...).eq(..).find(..).find(..)[0].innerHTML is undefined

Upvotes: 0

Views: 2303

Answers (3)

wala rawashdeh
wala rawashdeh

Reputation: 433

I have solve the problem by altering the jquery to

value = $('#main-content .main-nav-c li').eq(0).find('a').text().trim().toUpperCase();

Upvotes: 0

sinisake
sinisake

Reputation: 11328

value = $('.main-nav .main-nav-c li').find('a').find('.headerV').html().trim().toUpperCase();

console.log(value);

You made small mistake - by using # (id selector), rather than . class selector.

Fiddle: http://jsfiddle.net/5MXWm/

Upvotes: 1

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382150

You should have logged your object to see what happens (you can for example do console.log(myJqueryObject.length)).

The problem here is that your selector is wrong : main-nav is a class not an id.

You probably wanted

$('#main-content .main-nav-c li')

Upvotes: 8

Related Questions