[英]Find the first img inside a div and place a new div below it
I am trying to place a div below an image with jquery using the code below but it doesnt work. 我正在尝试使用下面的代码在jQuery的图像下方放置一个div,但是它不起作用。
in the <head>
i have this code: 在
<head>
我有以下代码:
<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: 在
<body>
里面,我有这个:
<div class="gdl-blog-full">
<img src="logoF.png" width="400" height="93" />
</div>
I just want to place a <div>
below the image.. 我只想在图像下方放置一个
<div>
。
像这样 :
$('.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");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.