javascript - JQuery - get attr/text from HTML string in a variable -
i have html string i'm passing through function , want able perform jquery methods on variable inside function - such .attr('href')
or .text()
. i'm sure there simple solution , more elegant temporarily appending dom.
html
<div class="here"></div>
javascript
link = '<a href="http://www.google.com">google</a>'; // works $('.here').html(link); works = $('.here').text(); console.log(works); // doesn't not = link.text(); console.log(not);
you need create jquery object link
in order use jquery methods on it. try:
not = $(link).text();
demo: http://jsfiddle.net/dfgyk/1/
depending on you're doing link
, might beneficial earlier in code can use like:
var $link = $(link); console.log(link.text());
Comments
Post a Comment