[英]Need help selecting child div with jquery
I'm having a tough time with something that I think is pretty simple. 我很难过一些我认为很简单的事情。 I hope you folks can help me. 希望大家能帮助我。
I'm using a jquery plugin called zoomtoo . 我正在使用一个名为zoomtoo的jQuery插件。
I need to have the plugin function ( zoomToo()
) applied on a child div ( modal-img-wrap
) inside its parent div ( modal
). 我需要在其父div( modal
)内的子div( modal-img-wrap
zoomToo()
modal-img-wrap
)上应用插件功能( zoomToo()
)。
The JS script: JS脚本:
<script type="text/javascript">
$(function() {
$(".modal").zoomToo({
magnify: 1
});
});
</script>
The HTML code: HTML代码:
<body>
<div id="ex2" class="modal">
<div class="modal-img-wrap">
<img class="modal-img" src="homedrive.jpg" />
</div>
</div>
</body>
I'm confused, you can select the div by name $( "#MyDiv" ). 我很困惑,您可以按名称$(“ #MyDiv”)选择div。 Set the name property of the div. 设置div的name属性。
$(function() { $(function(){
$("#MyDiv").zoomToo({
magnify: 1
});
});
</script>
Here is a working example. 这是一个工作示例。 Notice the attributes in the divs. 注意div中的属性。 And bind the jquery.zoomtoo.min.js
script, because it's minified, eg smaller. 并绑定jquery.zoomtoo.min.js
脚本,因为它已缩小(例如较小)。 If you already have a css class on the image containing div ( modal-img-wrap
), then you can also directly reference it inside js. 如果在包含div( modal-img-wrap
)的图像上已经有一个CSS类,那么您也可以在js中直接引用它。 So, instead of .modal .modal-img-wrap
you can write .modal-img-wrap
in js script. 因此, .modal .modal-img-wrap
您还可以在js脚本中编写.modal-img-wrap
。
Good luck. 祝好运。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes" />
<meta charset="UTF-8" />
<!-- The above 3 meta tags must come first in the head -->
<title>Demo</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="dist/jquery.zoomtoo.min.js"></script>
<script type="text/javascript">
$(function () {
$(".modal-img-wrap").zoomToo({
magnify: 1
});
});
</script>
</head>
<body>
<div id="ex2" class="modal"><!-- Not this div -->
<div class="modal-img-wrap" data-src="homedrive_big.jpg"><!-- I need this div selected by the plugin. -->
<img class="modal-img" src="homedrive_normal.jpg" />
</div>
</div>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.