Refael
asked on
Data Attribute Setting
Hello Experts,
For some reason the code below always set the "haus" variable to "street 003" , no matter if the data-haus is set in the area to "4".
Can you have a look and correct me?
For some reason the code below always set the "haus" variable to "street 003" , no matter if the data-haus is set in the area to "4".
Can you have a look and correct me?
<area shape="poly" id="unit15" coords="7,167,6,268,216,264,216,167" href="#" data-haus="1" data-sqm="200.01">
if ($("area").data('haus') === "1") {
var haus = "Street 003";
} else {
var haus = "Street004";
};
It looks fine. I guess the issue may resides where you set data-haus to 4. Can you show that part?
ASKER
Brian Tao, Thank you.
Right after the script above I have the following script. The "qtip" is a tooltip plugin and i am passing the variable "haus" to the tooltip.
Right after the script above I have the following script. The "qtip" is a tooltip plugin and i am passing the variable "haus" to the tooltip.
jQuery("area").each(function() {
jQuery(this).qtip({
content: {
text: 'haus',
},
.............
That's not what I meant. You're USING haus here. Where do you SET the data-haus attribute? It's literally "1" in your first post.
ASKER
Brian Tao I am not sure what you mean. The area shape html I posted above. Here it is again.
<area shape="poly" id="unit15" coords="7,167,6,268,216,264,216,167" href="#" data-haus="1" data-sqm="200.01">
Yes, you have data-haus="1" in it. So why are you complaining the if statement always setting haus = "Street 003"?
The logic in your code says if data-haus is "1" then haus = "Street 003". Since it IS "1", of course haus is always "Street 003"!
The logic in your code says if data-haus is "1" then haus = "Street 003". Since it IS "1", of course haus is always "Street 003"!
ASKER
Brian Tao,
This was one example, I have more more code on the page and many have the "haus" data equal to different values .
I think you did not read the question.
This was one example, I have more more code on the page and many have the "haus" data equal to different values .
I think you did not read the question.
Well I did. That's why I was asking for the part of code where you set the "haus" data to different values. Or better yet, paste the entire code or provide a link to your page.
ASKER
Hello Brian Tao,
I had to add the "this" to the "each" function so it will refer to each "area".... I did not notice that!
So after the "each" function, in the if statement refer to the "this" :-)
" if($(this).data('haus') === "1") { }"
I had to add the "this" to the "each" function so it will refer to each "area".... I did not notice that!
So after the "each" function, in the if statement refer to the "this" :-)
" if($(this).data('haus') === "1") { }"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.