[英]How to get value of the firs child inside the div using Jquery by the <a>
Here is the div: 这是div:
<div class="dropdown-menu">
<a class="dropdown-item" value="1">Try1</a>
<a class="dropdown-item" value="2">Try2</a>
<a class="dropdown-item" value="3">Try3</a>
<div>
And here is Jquery: 这是Jquery:
$(document).ready(function() {
$("#dropdown-menu div:first-child").attr("value");
animalidd = $(this).attr("value");
aler(animalidd);
});
I just need the value of the first child that is selected automatically also after refresh and no i need it with <div>
and <a>
我只需要刷新后自动选择的第一个孩子的值,不需要
<div>
和<a>
You have to use the following selector : "div.dropdown-menu a:first-child" 您必须使用以下选择器:“div.dropdown-menu a:first-child”
$(document).ready(function() {
var animalid = $("div.dropdown-menu a:first-child").attr("value");
alert(animalid);
});
Here is a working example : https://codepen.io/andreds/pen/vpamGm 这是一个工作示例: https : //codepen.io/andreds/pen/vpamGm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.