jquery, get id of dropdownlist when button is clicked
My dom looks like:
<td>
<select id=s1 c开发者_开发技巧lass=c1>...</select>
<select id=s2 class=c1>...</select>
<select id=s3 class=c1>...</select>
<input type=button id=btn value=click/>
</td>
Now when the page loads, I do a $(".c1").hide();
and then based on other logic, make one of them visible.
Now when the button is clicked, I want the ID of the drop down list that is currently visible.
How can I do this?
$("select.c1:visible").attr("id")
Should return you the ID of the first visible select element.
Also please quote your attribute values.
$('#btn').click( function(){
$('select.c1:visible').get(0).id
});
$("select:visible").attr("id")
BTW, you should be aware that IDs are not the only way to find and handle elements in JavaScript. I mean that $("select:visible")
already contains the element itself!
精彩评论