Need help with JavaScript library "JQuery"
I seek your help with the JavaScript library "JQuery". My goal is to recover a portion of the contents of a variable that contains HTML.
For example:
HTML Code:
var data = "<html> <head .............</ html>";
My goal is to recover (to put in a variable) an element whose id = 'foo' for example.
If you have any ideas, please help!
Re: Need help with JavaScript library "JQuery"
According to me, it is
$ ('foo')
Re: Need help with JavaScript library "JQuery"
Sorry but no.
$ ('foo') with prototype or $ ( '# foo') with JQuery retrieves the element if the damage is loaded. Basically, HTML is in the current page.
My problem is different because the HTML code is in a variable.
Re: Need help with JavaScript library "JQuery"
From this document: http://docs.jquery.com/Core
HTML Code:
$ (my_var ).$ ('# foo ')
Re: Need help with JavaScript library "JQuery"
I did not succeeded with your method. However, reading the document more closely, I read: "Create DOM elements on-the-fly".
The solution to my problem is here: http://docs.jquery.com/Core/jQuery# htmlownerDocument
A small example of implementation
Code:
$ (). ready (function () {
$ ( "# mylink"). click (function () {
var mycodehtml = "<p> my para <span id='foo'> <strong> Myfoo </strong> </span> </p>";
var foo = $ ( "# foo", mycodehtml). html ();
alert (foo);
});
});
HTML Code:
<a id = "mylink"> click </a>
Always be persistent