unammedkiller
unammedkiller

Reputation: 89

uniquely identify html id

<div id=Apple1>
    <div id=Round></div>
</div>
<div id=Apple2>
    <div id=Round></div>
</div>
<div id=Apple3>
    <div id=Round></div>
</div>
<div id=Apple4>
    <div id=Round></div>
</div>
<div id=Apple5>
    <div id=Round></div>
</div>

$("#Apple1 #Round")
$("#Apple2 #Round")
$("#Apple3 #Round")

Basically i have multiple div different wrapper div id and same inner div id.

can i use jquery this way to uniquely identify div tag?

Upvotes: 0

Views: 337

Answers (7)

Miqdad Ali
Miqdad Ali

Reputation: 6147

Yes dude .

You can use this. But ID must be unique. So its better make it class

Upvotes: 0

user1432124
user1432124

Reputation:

<div id=Apple1>
    <div></div>
</div>
<div id=Apple2>
    <div></div>
</div>
<div id=Apple3>
    <div></div>
</div>
<div id=Apple4>
    <div></div>
</div>
<div id=Apple5>
    <div></div>
</div>

$("#Apple1").children()
$("#Apple2").children()
$("#Apple3").children()

Upvotes: 0

Brice Favre
Brice Favre

Reputation: 1527

Id must be unique. You must use class instead of your id "round".

<div id="Apple1">
    <div class="Round"></div>
</div>
<div id="Apple2">
    <div class="Round"></div>
</div>
<div id="Apple3">
    <div class="Round"></div>
</div>
<div id="Apple4">
    <div class="Round"></div>
</div>
<div id="Apple5">
    <div class="Round"></div>
</div>

Than you can query jquery this way:

$("#Apple1 .Round")
$("#Apple2 .Round")
$("#Apple3 .Round")

Upvotes: 0

charlietfl
charlietfl

Reputation: 171679

You can't repeat ID's in a page, they must be unique. Switch your repeating ID's to class

<div id=Apple1>
     <div class=Round></div>
 </div>

Then you do what you were trying originally

 $('#Apple1 .Round').doSomething()

Upvotes: 0

ninja
ninja

Reputation: 2263

id must be unique, use a class for "Round" instead, then to target identify the round inside a unique id div.

$('#Apple1 .Round')

Upvotes: 0

Andreas Wong
Andreas Wong

Reputation: 60516

id by definition should be already unique, I'll go as far as saying it's invalid to have more than one of the same id in a HTML page.

You can use class if you want:

<div id="Apple1">
   <div class="Round">
</div>
...

Then

$('#Apple1 .Round');
//etc

Upvotes: 4

lanzz
lanzz

Reputation: 43168

Yes, you can, but having multiple elements with the same id is not valid HTML under any standard.

Upvotes: 0

Related Questions