I’m very new to jQuery and I am having an issue with parsing a string value to a function.
I have:
function callAreaData(area) {
$("area[alt='" + area + "']").hover(function (e) {
$("div#bodyPlace_popupA").show();
$("area[alt='" + area + "']").hide();
}, function () {
$("div#bodyPlace_popupA").hide();
});
$("area[alt='" + area + "']").mousemove(function (e) {
$("div#bodyPlace_popupA").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft);
});
}
and call it within my
$(document).ready(function () {
...
var a = "Area A";
callAreaData(a);
...
});
It does not work. I know the function itself works because if I replace the parsed values in the function with their string equivalent, as below, it works fine. But that doesn’t give me the re-usability I need (as I need to used this function about 10 times over with a different parameter on my web page).
function callAreaData() {
$("area[alt='Area A']").hover(function () {
$("div#bodyPlace_popupA").show();
$("area[alt='Area A']").hide();
}, function () {
$("div#bodyPlace_popupA").hide();
});
$("area[alt='Area A']").mousemove(function (e) {
$("div#bodyPlace_popupA").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft);
});
}
It’s got to be an easy fix, but I can’t see it, so help please?
Thanks in advance, Peter
Try Something like:
$(document).ready(function() { var area = someArea; // get area from some hidden element $("area[alt='" + area + "']").hover(function (e) { $("div#bodyPlace_popupA").show(); $("area[alt='" + area + "']").hide(); }, function () { $("div#bodyPlace_popupA").hide(); }); $("area[alt='" + area + "']").mousemove(function (e) { $("div#bodyPlace_popupA").css('top', e.pageY + moveDown).css('left', e.pageX + moveLeft); }); });