Reputation: 99
Can help me please with a jquery object problem.
The problem is the following, I have this code:
url = '<a href="http://url.com">Name</a>';
otherValue = "Other Value";
x = jQuery(url).text(otherValue);
console.log(x);
console.log(typeof(x));
This return :
[<a href="http://url.com">Other Value</a>]
object
How I make for cast this object and finally get a string?
Thank's
Upvotes: 0
Views: 565
Reputation: 3825
Check out this link.
url = '<a href="http://url.com">Name</a>';
otherValue = "Other Value";
x = jQuery(url).text(otherValue);
alert(x[0].outerHTML);
Upvotes: 0
Reputation: 160833
Try console.log(x[0].outerHTML);
Explain: x[0]
gives you the HTMLAnchorElement
object, HTMLAnchorElement.outerHTML
gives you the html string.
Upvotes: 2