Nihal Sahu
Nihal Sahu

Reputation: 189

'object Object' in firefox wehn referencing jquery?

First time i've used jquery and I'm in trouble . I used the following code in html :

<ul>
    <li>hello </li>
    <li>hello 2</li>
    <li>hello 3</li>
</ul>
<script type="text/javascript" src="jquery-2.0.3.js"></script>

<script type="text/javascript">
var lis = jQuery('ul li')
console.log(lis)
</script>

When I checked my version , It was 2.0.3 .

But I opened firefox and used Inspect element to check the console , it returns

[17:57:32.367] [object Object]
instead of [<li>hello</li>]

Actually I'm learning via Tuts free courses (Hello Jquery by jeffery way) at this link; and he gets different output

Upvotes: 1

Views: 1004

Answers (2)

aksu
aksu

Reputation: 5235

It returns that because it's just jquery object(element). You are just selecting that list item, not the content in it. Add .text() function to your variable for getting contents of selector:

var lis = jQuery('ul li').text();
console.log(lis);

Upvotes: 0

Bilal
Bilal

Reputation: 2673

Because jQuery('ul li') returns a DOM object. If you want to get internal html of li or ul then you can try it

jQuery('ul').html() // for ul internal html
jQuery('ul li').html() // for li html

or you can also use that object like jQuery(lis).html()

Upvotes: 1

Related Questions