Reputation: 913
I want to use content of one html page in another html page ... I have two page -> a.html & b.html in a.html I have paragraph with id="a" and in b.html I have paragraph with id="b" I want to have access of first paragraph in the second page. can you help me how to do it ?
<!------------a.html--------------------- -->
<html>
<head>
<title> a.html </title>
</head>
<body>`enter code here`
<p id="a"> aaa </p>
</body>
</html>
<!------------b.html--------------------- -->
<html>
<head>
<title> b.html </title>
</head>
<body>
<p id="b"> bbb </p>
<script>
document.getElementById("b").innerHTML = document.getElementById("a").innerHTML;
</script>
</body>
</html>
Upvotes: 0
Views: 50
Reputation: 71
You can store it in local storage
localStorage.text1 = document.getElementById("a").innerHTML;
Then you can retrieve form local storage and use as innerHTML
for ID b
document.getElementById("b").innerHTML = localStorage.getItem('text1');
Upvotes: 0
Reputation: 2308
This method is the simplest way to fetch data from the server. It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the returned data. This means that most uses of the method can be quite simple:
$( "#result" ).load( "<html resource path>" );
If no element is matched by the selector — in this case, if the document does not contain an element with id="result" — the Ajax request will not be sent.
Please review more about load method http://api.jquery.com/load/
Upvotes: 0
Reputation: 270
Try this :
var p = $('#a').text();
$('#b').text(p);
But you must use ajax to do that.
You can use load function then get id of paragraph from a page.
Because without ajax your content in another page is not detected
Upvotes: 1