I'm doing a jquery dropdown menu to change language on a site. As you can see in the code below I am storing languages in one array and images relating to those languages in another. When a button is clicked I want to look at the text in that button, get that text's index in the array, then use that index to add its image somewhere else.
At the moment I am getting no image at all. The variable btnText is working as I can see the result in #languageBtn, but something is not working on line 7 with indexOf. If I change line 7 to a string and not the btnText variable e.g. indexOf("Deutsch") it works fine and I get an image.
indexOf(something) only seems to work if something is not a variable but a string in quotes. Any ideas anyone?
languageArr = new Array("English", "Español", "Deutsch", "Français");
languageFlagArr = new Array("flag_en.gif", "flag_es.gif", "flag_de.gif", "flag_fr.gif");
I have a div that when clicked should run a function
$('#ratingOnScreen' + i).click(viewRowFunction);
The function itself gets the id of the div that was clicked to use later.
function viewRowFunction (e) {
var clickedId = $(e.target).attr('id').replace('ratingOnScreen', '');//gets just the index
$('#ratCodeId0').text(clickedId);
}
The problem is that the div contains child divs so sometimes these are being clicked and the viewRowFunction is getting the id of the child instead of the parent. Is any way of avoiding this? I have tried giving all the child divs a class of noIncClass and then using :not and .not() in various forms but this made no difference. e.g.
This is driving me crazy. I have many divs like the example below. when you click on one its class should change.
<div class="yesNoOpac"><span class="yesNoSpan">here is the text</span></div>
<script type="text/javascript" charset="utf-8">
$('.yesNoOpac').click(changeClassYesNoOpac); function changeClassYesNoOpac(e){ $(e.target).removeClass("yesNoOpac"); $(e.target).addClass("yesNoOpacX"); }
</script>
The class change changes the background image (aligned left) and the opacity of the div. This works ok for the div , but the problem I am having is that when I click on the text (aligned right) it is changing the class of the span element. I don't want the class of the span to change as that adds the background image to the span too so I end up with one background image for the div and another for the span that's in the div.
What I want is when I click the div anywhere it only changes the class of the whole div and not both the div and the span.
i have also tried this which gave the same result:
$('.yesNoOpac:not(.yesNoSpan)').click(changeClassYesNoOpac); function changeClassYesNoOpac(e){ $(e.target).removeClass("yesNoOpac"); $(e.target).addClass("yesNoOpacX"); }