JQuery: How To Get Attribute From An Object
I am having a problem getting the innerHTML from an object. At the moment I have this code: console.log( $(myString).find('#' + someID).prevObject ); myString is a string variabl
Solution 1:
You can get the HTML of an element via the jQuery html
function. So assuming the element with the ID really exists:
console.log( $(myString).find("#" + someID).html() );
That will give you what you said you wanted: The HTML of the li
with that id
. Note that I removed the prevObject
. Two reasons for that:
You said you wanted the HTML of the
li
with thatid
. If you do, you don't wantprevObject
.prevObject
is an undocumented aspect of jQuery. It can change meaning, change name, or go away entirely from one dot release to the next. (But mostly point #1.)
Solution 2:
You should get the html element from the jquery object like this:
console.log( $(myString).find("#" + someID).prevObject[0].innerHTML );
or you can access jquerys version of innerHTML
console.log( $(myString).find("#" + someID).prevObject.html() );
Solution 3:
Once you have the element you just need to use html().
$('div.demo-container').html();
See here for more information:-
Post a Comment for "JQuery: How To Get Attribute From An Object"