286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

Hey guys,

My aim is changing the class when user clicks to the search form, ie changing the search form’s text color when user wants to enter a search query.. (You know that from many sites, the default text of “Search..” in the box is a pale grey, but when you click the box to enter a search query, the text turns to a black etc to give it a more contrast..) so, I defined a .searchText class in css, and I want jquery to apply it when user clicks the search box. The problem is, when the page is loaded, the class is already added (ie the “Search..” text is already black, when it should be grey), but if you click once in it and click outside, it behaves right. I don’t know what is missing to make it behave right when the page is loaded. My code is:

$(document).ready(function(){
    $('#searchform').click(function() {
                $('#searchform input#s').addClass('searchText');
        });
});

so, what’s wrong here??

447 posts Don't be a HATER!
  • Has referred 10+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+5 more
webinpixels says

not click function but try to use focus function :)

good luck

286 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+3 more
AkinGn says

I solved it lol it was because of a css problem. Actually I tried this because I was trying to get familiar with jquery, I already can do it with pure css, with focus pseudo selector and I think I’m gonna use it. Thanks for your reply, webinpixels :)

by
by
by
by
by
by