-1

I have 2 html files a.html and b.html and i want to write some javascript code to the a.html file that can add, edit, or delete html code to the b.html file.

3
  • 1
    So we know what you wish to achieve, now lets have a look at what you have tried? Where is your source code (Attempts) and what isn't working? Where is the issue? Commented Aug 17, 2015 at 9:32
  • You might find this helpful stackoverflow.com/questions/1413691/… Commented Aug 17, 2015 at 9:51
  • Why is this marked as duplicate for Include html page? The OP isn't asking how to include anything. The OP is asking how to modify b.html from a.html Add/Edit/Delete elements, not include them. >> i want to write some javascript code to the a.html file that can add, edit, or delete html code to the b.html file << If this is going to be marked as duplicate I think the answer URL should be set to this: stackoverflow.com/questions/1413691/… Commented Aug 17, 2015 at 10:07

1 Answer 1

0

You have only one choice to use AJAX. If you are using jQuery, you can do something like:

$(function () {
  $("#b").load("b.html");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<p>I am in <code>a.html</code></p>
<p id="b">B comes here</p>

The above script is basically an AJAX request to load the contents of b.html that is found along with the a.html in the same directory, inside the <p> with an id of b.

Sorry, I forgot to mention. To make the AJAX call easier, I have added a library called jQuery, which provides a lot of functionality.

Sign up to request clarification or add additional context in comments.

6 Comments

This isn't going to edit or delete parts of the html file though is it? This is just going to load b.html into a.html I think what the OP is wanting is a.html to be the editor for b.html like a CMS
@NewToJS It replaces the contents inside the <p> tag alone. No changes to other parts. :)
Exactly, so a.html isn't adding/editing/removing existing content in b.html. This is just setting the innerHTML of the paragraph tag in a.html with the content from b.html
I haven't used jquery or AJAX before so i just copy this? There isn't another way so I can also edit or remove code?
This also requires jQuery which isn't tagged in the question so I think it would be very relevant to point out how to link to the jQuery library as people who are new to development may not know how to do so hence it not being tagged.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.