0

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

2
  • Are you trying to get the String representation of <a href... ? Commented Jul 6, 2012 at 3:37
  • Yes!! I want get the string representation!! Commented Jul 6, 2012 at 3:40

2 Answers 2

2

Try console.log(x[0].outerHTML);

Explain: x[0] gives you the HTMLAnchorElement object, HTMLAnchorElement.outerHTML gives you the html string.

Sign up to request clarification or add additional context in comments.

1 Comment

Now I have this problem: may be than outerHTML replace me ">" "<" characters ?? <a href="url.com/place/mr-mofongo/">&lt;span class="ac_match"&gt;Name&lt;/span&gt;</a>
0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.