How to get content of element by id from HTML object using JavaScript (JQuery)
I will write the following code to access the "jQueryPage.aspx" page and receive data from it using jQuery
<script type="text/javascript">
$.get
(
"JQueryPage.aspx",
function(data) {
alert("Data Loaded: " + data);
}
);
</script>
"JQueryPage.aspx" is just a page containing a DIV called "resultsDIV" which contains the data I want to return the
above code return data variable containing the html "JQueryPage.aspx" and I want to get the content of the DIV from it ..
I have 2 questions:
1- how can I extract the content of the DIV from the data object
2- is this the best way to get this data?
+2
a source to share
3 answers
- If the html markup is
JQueryPage.aspx
valid xml, you can use the dom parser to get the div you want. - It depends if you want to add the resulting html to the existing DOM with a call
document.appendChild
, yes. But if you need to parse and read values from the extracted data, no, it is not. Pass the data as JSON or xml string.
0
a source to share