javascript - Get only property from object has only one property JQuery -


how property js object. when used $('body') return in object form , other times return property how can perform task on property. like..

$('body').html();  // return in object // [<body></body>] // or sometime return // <body></body> // if return in object got error like. 

uncaught typeerror: $(...).html not function

how can make return property consistent? because want use in condition , can't use if want use every time in object or 1 property.

if returns in object want use eq() don't know when return in object form , when return property how can use eq() because not use property.

sometime means nothing in code. if there code defined $ (which happen), can replace jquery $ function $j.

var $j = jquery; 

that's how can sure jquery object return, can use eq without worry.

for example:

$j('your_selector').eq(0); 

live example

var $j = jquery;    console.log($j('div').eq(0).html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>    <div>test text</div>


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -