I'm using PHP and an ajax command to take the entire HTML contents of an external web page (via the PHP file_get_contents()
command) and passing that HTML into a javascript variable. Once I have the page's HTML contents stored in a variable, can I use jQuery to interact with the contents of that variable, in the same way that jQuery normally interacts with the DOM? In this example, I am trying to search for the existence of certain HTML elements (<div>
and <script>
tags) with specific ID attributes. Can anyone suggest how I can accomplish this?
If I understand you correctly, you should be able to just pass the variable to the jQuery function and work accordingly.
A quick example with .filter()
:
$(myHtml).filter('#someid').doStuff();
Just pass it as a string to the jQuery constructor.
var foo = jQuery('<p><b>asd</b><i>test</i></p>').
alert(foo.find('i').text());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With