Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
177
rated 0 times [  180] [ 3]  / answers: 1 / hits: 28023  / 14 Years ago, tue, july 27, 2010, 12:00:00

I am creating a survey form that needs to have each question and set of answers highlighted (by changing the background color) when the user focuses on them. .focus() and .blur() both work in Firefox and IE, but not entirely in Safari and Chrome. I also tried .focusin() and .focusout() with the same results. EDIT: Clicking does not fire the focus event, but tabbing through the input fields does. I say not entirely because it works for text inputs, select inputs and textarea inputs; but not radio and checkbox inputs.



$(document).ready(function()
{
$(form li).focusin(function()
{
$(this).addClass(over);
}).focusout(function()
{
$(this).removeClass(over);
});
});


This is being applied to blocks of html similar to this:



<li>
<label for=webmail class=desc>Email</label>
<input type=text name=webmail id=webmail />
</li>
<li>
<label for=business class=desc>Purpose of your Charter Flight:</label>
<div>
<span>
<input type=radio name=purpose id=business class=radio />
<label class=choice for=business>Business</label>
</span>
<span>
<input type=radio name=purpose id=pleasure class=radio />
<label class=choice for=pleasure>Pleasure</label>
</span>
</div>
</li>


I tried messing around with toggles, but I am looking for a more elegant solution that doesn't involve using convoluted logic to make it work. Any ideas?


More From » webkit

 Answers
4

I thought about it on the drive home last night and figured it out on my own, it may not be the most elegant solution, but it certainly works.



$(document).ready(function()
{
$(textarea, input, select, .radio, .checkbox).click(function()
{
$(form li.over).toggleClass(over);
$(this).parents(li).toggleClass(over);
});
});


Thanks anyway!


[#96097] Saturday, July 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
debras

Total Points: 307
Total Questions: 98
Total Answers: 112

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
;