Link to home
Create AccountLog in
Avatar of Refael
RefaelFlag for United States of America

asked on

jquery select elements with same ID

Hi guys,

when a user click on a DIV with class name "object-title" i need to show (on hover) the relevant DIV with the class name "object-desc" but with the same ID. Tha't why i i use the substring so i can match the ID's of both selectors. Yet i do not know how to complete the script.

<div class="object-title" id="objekt-title-num1">text text text <div>
<div class="object-title" id="objekt-title-num2">text text text <div>
<div class="object-title" id="objekt-title-num3">text text text <div>

<div class="object-desc" id="num1-desc">text text text</div>
<div class="object-desc" id="num2-desc">text text text</div>
<div class="object-desc" id="num3-desc">text text text</div>

Open in new window



$('.object-title').hover(function() {

    var titleId = $(this).attr("id").substring(13);     // we have "num1"
    var descId = $(".object-desc").attr("id").substring(0, 4);   // we have "num1"
   ?  

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Refael

ASKER

leakim971 and sedgwick thank you so much!
Or as another way to make it future proof if you ever change the id, or just for ease of reading

<div class="object-title" id="objekt-title-num1" rel="num1-desc">text text text <div>

$('.object-title').hover(function() {
    var descId = $(this).attr("rel")
Avatar of Refael

ASKER

thank you guys!