I am trying to place a div below an image with jquery using the code below but it doesnt work.
in the <head>
i have this code:
<script type="text/javascript">
$( document ).ready(function() {
$(".gdl-blog-full").find("img").prepend("<div id='1' style='width:400px; float: left; margin-top:10px; background-color: #000;'> You are watching 5th object out of 100 </div>");
});
</script>
and inside the <body>
i have this:
<div class="gdl-blog-full">
<img src="logoF.png" width="400" height="93" />
</div>
I just want to place a <div>
below the image..
像这样 :
$('.gdl-blog-full>img:first-child').after("<div>hello</div>");
使用$ .after
$('.gdl-blog-full').find('img:first-child').after('<div id='1' style='width:400px; float: left; margin-top:10px; background-color: #000;'> You are watching 5th object out of 100 </div>');
使用.after
将元素放置在指定元素之后,也使用:first-child
获得第一个图像:
$(".gdl-blog-full").find("img:first-child").after("<div id='1' style='width:400px; float: left; margin-top:10px; background-color: #000;'> You are watching 5th object out of 100 </div>");
not prepend it should be after
<script type="text/javascript">
$( document ).ready(function() {
$(".gdl-blog-full").find("img").after("<div id='1' style='width:400px; float: left; margin-top:10px; background-color: #000;'> You are watching 5th object out of 100 </div>");
});
</script>
使用.insertAfter将元素放在另一个之后。
$("<div id='1' style='width:400px; float: left; margin-top:10px; background-color: #000;'> You are watching 5th object out of 100 </div>").insertAfter(".gdl-blog-full img:first-child");
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.