themistral Posted November 30, 2011 Share Posted November 30, 2011 Hi guys, I am using jquery to add a class to an input box on a focus event. $('input').focus(function() { $(this).addClass("focus"); }); It works but only if I tab to the input box - if I click in the box the code doesn't work. I've tried changing the code to $('input').click(function() { $(this).addClass("focus"); }); but that isn't working either. Can anyone shed any light? Quote Link to comment https://forums.phpfreaks.com/topic/252107-jquery-focus/ Share on other sites More sharing options...
Spring Posted November 30, 2011 Share Posted November 30, 2011 Looks correct to me, you can try this if you want. $("input").live("click", function(){ $(this).addClass("focus"); }); Also there could be another part of your Jquery incorrect that's breaking the script. Quote Link to comment https://forums.phpfreaks.com/topic/252107-jquery-focus/#findComment-1292613 Share on other sites More sharing options...
themistral Posted November 30, 2011 Author Share Posted November 30, 2011 Ah, good call! Took out my other javascript as a test, and it's working! Just need to sort out that conflict Thanks Spring!! Quote Link to comment https://forums.phpfreaks.com/topic/252107-jquery-focus/#findComment-1292657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.