Refael
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.
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>
$('.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"
?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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(f unction() {
var descId = $(this).attr("rel")
<div class="object-title" id="objekt-title-num1" rel="num1-desc">text text text <div>
$('.object-title').hover(f
var descId = $(this).attr("rel")
ASKER
thank you guys!
ASKER