简体   繁体   中英

javascript or jquery to change innerHTML of a div?

This function allow me to load a webform/popup above my page test.aspx

  $(document).ready(function () {
  $('#<%= webform.ClientID %>').load('pop_up_one.html');})

I now would like to change the innerhtml of this popup with another popup and have the possibility to come back to the first popup. Basicly I just want to change the innerhtml of the DIV of the first pop_up

How is possible to do that? thought adding something like:

   $('#div_of_popup_one').click.load('pop_up_two.html');

but this does not work.

The only way I found to make it work has been to integrate this code into pop_up_1-html:

    function loadextPage(event) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById('name_of_div_to_change').innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", event.target.href, true);
        xmlhttp.send();
    }

and call this from:

Go to second pop up

This method works but i would like to do it with something like

        $('#div_of_popup_one').click.load('pop_up_two.html')

from the page i am calling the pop_up_one

To do this, first you need to, bind click event and then invoke click . Use the following code.

   $('#div_of_popup_one').on("click", function() {
       $(this).load('pop_up_two.html');
   });

   $('#div_of_popup_one').click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM