291 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??

451 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
+6 more
webinpixels says

not click function but try to use focus function :)

good luck

291 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 :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by