简体   繁体   English

基于ID的div中div的jQuery选择器

[英]JQuery selector for div within div based on id

I have the following classic ASP: 我有以下经典ASP:

<div class="TabContent">
<%
for i = 1 to 6
%>
    <div id=<%=i%>>
        TabDetail = <%=i%>
    </div>
<%
next
%></div>

I'm trying to access a single div element with the following JQuery selector: 我正在尝试使用以下JQuery选择器访问单个div元素:

$(".TabContent > div#1")

But it's not finding it. 但是找不到。 There's definitely a div with an id of 1, so I can't figure out why it's not working! 绝对有一个id为1的div,所以我不知道为什么它不起作用!

Any help would be appreciated. 任何帮助,将不胜感激。

I'm not too familiar with asp. 我对ASP不太熟悉。 But if you're following good practice, each ID should only be used once on a page. 但是,如果您遵循良好做法,则每个ID在页面上只能使用一次。 So if there is only one tag with the ID of "1" you can just use jquery as: 因此,如果只有一个ID为“ 1”的标签,则可以将jquery用作:

$("#1")

Make sure that id isn't being used elsewhere. 确保该id未在其他地方使用。 Your code does work fine: https://jsfiddle.net/jay08tbz/ 您的代码工作正常: https//jsfiddle.net/jay08tbz/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM