Reputation: 227
i have a Problem my Area Shape href="/kosmetikstudios/deutschland/Bayern" tag look so. And i will to use the Parameter "Bayern" (this is the last parameter of the url).
I need this dynamic.
Here are my Javascript Code:
<script type="text/javascript">
$(document).ready(function(){
var mName="passiv";
$("#map area").mouseenter(function(){
mName = $(this).attr("href"); // i don't have idea to implement this
bName="images/" +mName + ".png";
$("#map img").attr("src",bName);
});
$("#map area").mouseleave(function(){
bName="images/Europa.png";
$("#map img").attr("src",bName);
});
});
</script>
Here are my HTML Code
<area shape="poly" coords="356,300,355,299,354,298....." href="/kosmetikstudios/deutschland/Bayern" title="Kosmetikstudios in Bayern" alt="Kosmetikstudios in Bayern" />
<area shape="poly" coords="156,200,425,699,154,298....." href="/kosmetikstudios/deutschland/Berlin" title="Kosmetikstudios in Berlin" alt="Kosmetikstudios in Bayern" />
I hope anybody can help me.
Regards,
Dave
Upvotes: 0
Views: 105
Reputation: 99
Instead of extracting the value out of the URL you could set a data attribute to store the name.
For example:
HTML
<area shape="poly" data-name="Bayern" href="/kosmetikstudios/deutschland/Bayern" />
<area shape="poly" data-name="Berlin" href="/kosmetikstudios/deutschland/Berlin" />
JS
<script type="text/javascript">
$(document).ready(function(){
var mName="passiv";
$("#map area").mouseenter(function(){
//read the data attributes
mName = $(this).data("name");
bName="images/" +mName + ".png";
$("#map img").attr("src", bName);
});
$("#map area").mouseleave(function(){
bName="images/Europa.png";
$("#map img").attr("src",bName);
});
});
</script>
Upvotes: 1
Reputation: 49919
You can do this:
mName = $(this).attr("href").split("/").reverse()[0];
Upvotes: 0