Reputation: 19
As when i scroll down the mouse more content are loaded in html page?Is there any way that i can access all this content without scrolling down the mouse using javascript?
var contents = document.getElementsByTagName("div")
this code give div of a html page(without scrolling).
Upvotes: 0
Views: 75
Reputation: 6014
It depends on how the content is loaded. If its just invisible, you can get it this way. But in most cases the content is loaded dynamically, means if the user scrolls to some point, the page sends an ajax request for more content to the server. When the server sends back the data, javascript updates the page. In this case you can't do anything, because it's not possible to send cross-domain ajax-requests.
Upvotes: 0
Reputation: 9269
You want to access content that is not loaded? You can't...
Upvotes: 1
Reputation: 43479
Use innerHtml
:
contents = document.getElementsByTagName("div");
console.log(contents[0].innerHTML);
Or if you are using jQuery, add some ID to that div, that you want it's content:
<div id='divId'>Hello <span>World</span></div>
$('#divId').text(); // Will return "Hello World"
$('#divId').html(); // Will return "Hello <span>World</span>"
Upvotes: 0