mike99c
asked on
How do I hide a tag in jQuery within HTML loaded via AJAX
This post is actually a continuation of the following:
https://www.experts-exchange.com/questions/28360042/jQuery-does-not-trigger-on-HTML-loaded-via-AJAX-call.html
I now want to hide a link within the loaded HTML.
The parent code is here:
The HTML to load is here:
I am trying to hide internallink2 but the following jQuery does not work:
$('#internallink2').hide() ;
I know this somehow needs to change but not exactly sure what the syntax is as this time the trigger is the HTML snippet loading.
https://www.experts-exchange.com/questions/28360042/jQuery-does-not-trigger-on-HTML-loaded-via-AJAX-call.html
I now want to hide a link within the loaded HTML.
The parent code is here:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
$('#internaldiv').load('link.htm');
$('#internallink2').hide();
$(document).on("click",".link",function(){
alert("Link clicked");
return false;
});
});
//]]>
</script>
<a class="link" href="#">Click parent link</a>
<div id="internaldiv">
</div>
</body>
</html>
The HTML to load is here:
<a class="link" href="#">Click loaded link</a><br>
<a class="link" id="internallink2" href="#">Click loaded link 2</a>
I am trying to hide internallink2 but the following jQuery does not work:
$('#internallink2').hide()
I know this somehow needs to change but not exactly sure what the syntax is as this time the trigger is the HTML snippet loading.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It's asynchronous
A synchronous call would block all further processing until the current function has finished - but this should not be used/or at the very least avoided.
A synchronous call would block all further processing until the current function has finished - but this should not be used/or at the very least avoided.
ASKER
Open in new window
So the synchronous AJAX call now does the load as well.