This is what I'm loading HTML into...
<div id="AJAX_Parent" class="visibleBorderThick">
<div id="AJAX_Child">
...
</div>
</div>
This is the link that loads the HTML using jquery's load function.
<a id="MyID_1755055367" class="dynamicLink" href="/rules"> Click Me </a>
This is the javascript that makes sure javascript and jquery are running...
<script type="text/javascript">
alert("Javascript is running");
if (window.jQuery) {
alert("jQuery is loaded")
} else {
alert("jQuery is not loaded")
}
if ( $( "#MyID_1755055367" ).length ) {
alert("Found element"); /* Element is found */
alert( $( "#MyID_1755055367" ).length ); /* length is 1*/
} else {
alert("Cannot Find Element")
}
</script>
This is the javascript that actually does the loading...
$("#MyID_1755055367").onclick = (function() {
alert("onclick activated");
history.pushState({ linkSource: window.location.href }, "page title", "/rules");
$("#AJAX_Parent").load("/rules #AJAX_Child");
return false;
});
^ This does not work. I am not seeing "onclick activated"
Also, I have tried doing it like this...
document.getElementById("MyID_1704232995").onclick = (function() {
alert("onclick activated");
history.pushState({ linkSource: window.location.href }, "page title", "/rules");
$("#AJAX_Parent").load("/rules #AJAX_Child");
return false;
});
Doing it this way gives me
"onclick activated"
, and I see the URL changed and when I look at the page source in Google Chrome, I see that the HTML pertaining to<div id="AJAX_Child">
has been modified.That's all good, but the page doesn't render correctly (it renders flat - as if
AJAX_Child
were an empty div). NOTE: FIXED THIS "FLATTENING" BY MOVING ID INTO "". DOLLAR SIGN LOADING STILL DOESN'T WORK.
* Fixed the jquery *
$(@{ Html("\"" + "#" + uniqueID.body.substring(1)) }).click(function() {
alert("onclick activated");
history.pushState({ linkSource: window.location.href }, "page title", @quotedURL);
$("#AJAX_Parent").load(@{ Html(quotedURL.body.dropRight(1) + " #AJAX_Child\"") });
return false;
});
* Now forward click works, but back button not working (back button causes HTML to change inside "page source", but page remains unchanged) *