Below is a main.html
page which dynamically appends two div
s with ids 'foo' and 'bar'. Problem is that using Chrome (v50.0.2661.102) browser I can not make page jump to a 'bar' div
, which is loaded from file, by appending #bar to the URL ( www.foo.bar/main.html#bar
), but I can do so for 'foo' ( www.foo.bar/main.html#foo
) div
, which was plainly appended to body
. It looks that it is due to .load()
function being asynchronous. I have no such problem in Firefox or IE. Is there a way to get around this issue?
main.html:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script>
$(function() {
$("<div>").load("bar.html #bar", function() {
$('body').append($(this).html());
});
$( 'body' ).append("<div id='foo' style='background-color:#8F8;'>FOO</div>");
});
</script>
</head>
<body>
<div style="height:150%; background-color:#FF8;">Lorem ipsum</div>
</body>
</html>
bar.html:
<div id='bar' style="background-color:#88F;">BAR</div>