How to get subset of string using Javascript/JQuery/JSON? -


I want to get a subset of a string in javascript. Currently, I only know how the entire string is stored:

I have this as a JSON variable, which is called foo:

  Foo ({"result": ["& lt; div id = \" the following \ "& gt; & lt; span & gt; & lt; a href = \" http: //twitter.com/barackobama \ "& Gt; Obama & lt; / a & gt; & lt; / span & gt; & lt; / div & gt; "]})  

and this is my callback function: < / P>

  function foo (o) {var wholeDiv = o.results [0]; }  

How do I archive tags in the form of a string in javascript " ...?

With jQuery, you can parse a piece of HTML in the form of another argument You can.

Then, update your foo function:

  $ j = jQuery.noConflict (); Function Fu (O) {var JustTheLink = $ j ('a', o.results [0]). Parent (). Html (); }  


Update:
To handle with multiple links, you can:

  function foo (o) {$ j ('a', o result [0]). Each (handle SRC); } Function handleSrc () {console.log (this); // tag console.log ($ j (this) .html ()); // content}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -