0

i got this jquery script, it puts placeholder "+" in my search input, and probblem is that, now every input got "+" placeholder on my website,

how to add only particulary class to this js code:

$( document ).ready(function() {
    $('input').on('focus',function(){
    $(this).attr('placeholder',"");
});
$('input').on('blur',function(){
    $(this).attr('placeholder',"+");
});

});
3
  • Just call addClass with your class in $(this)? jQuery addClass Commented May 25, 2016 at 13:25
  • 1
    Put the class name in the selector... $("input.className") Commented May 25, 2016 at 13:29
  • As Archer said you can select something like this $("input.myClass[type=text]") Commented May 25, 2016 at 13:33

2 Answers 2

1

This is quite simple jQuery code. A google search would have found you an answer. You just need to specify the class name:

$( document ).ready(function() {
  $('input.CLASSNAME').on('focus',function(){
    $(this).attr('placeholder',"");
  });
  $('input.CLASSNAME').on('blur',function(){
    $(this).attr('placeholder',"+");
  });
});
Sign up to request clarification or add additional context in comments.

Comments

0

Use an identifier like class or id where you want to update the placeholder

Hope this snippet will be usefull

JS

$( document ).ready(function() {
    $('input').on('focus',function(){
    $(this).attr('placeholder',"");
});
// add placeholder to input which have class updatePlaceholder
$('input.updatePlaceholder').on('blur',function(){
    $(this).attr('placeholder',"+");
});

});

HTML

<input type = "text">
<input type = "text" class = "updatePlaceholder">

Check this jsFiddle

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.