Marcelo
Marcelo

Reputation: 99

jQuery object cast to string

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

Answers (2)

Shiv Kumar Ganesh
Shiv Kumar Ganesh

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);

http://jsfiddle.net/SRjfq/

Upvotes: 0

xdazz
xdazz

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

Related Questions