开发者

Load callback and show div jQuery

$('#mydiv').load('index.php #mydiv', function() {
    $('#mydiv').show();
});

<div id="mydiv" style="display: none;">
    Some text
</div>

"Some text" never displays with this code when I run the function, the div displays though. But if I remove display: none,开发者_高级运维 everything displays when I run the function. This has never been a trouble for me before.

What´s wrong?

Thanks!


It looks like you're trying to load a single element with id "myDiv" from "index.php", and place that loaded element inside an element with id "myDiv". Doing so will result in two elements on the page with the same ID, and that's not valid.

Try changing either the ID of the div that you load the content into, or the ID of the element that you are loading:

$('#mydiv2').load('index.php #mydiv', function() {
    $('#mydiv2').show();
});

<div id="mydiv2" style="display: none;">
    Some text
</div>


display: none means visibility of the div is set to Hidden

The display property specifies if/how an element is displayed, and the visibility property specifies if an element should be visible or hidden.
Difference between Display and visibility in css

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜