-2

How to use jquery contains for textbox,I have attached the fiddle link for your code reference,

<div id="txtCon">
  <input type="text" name="man-news" />

  <input type="text" name="milkman" />
  <input type="text" name="letterman2" />
  <input type="text" name="newmilk" />
    has
</div>


Script:


$('input[name*="new"]').val('has');

$('input:text:contains("has")').css("color","red");

Link:

http://jsfiddle.net/vigneshjayaraman/Ytsr5/2/

Vignesh
  • 1,458
  • 12
  • 31
  • 59
  • I think you understand wrong the contains selector,pls take a look at this : http://www.w3schools.com/jquery/jquery_ref_selectors.asp – Duc Anh May 02 '13 at 04:13
  • Possible duplicated [here](http://stackoverflow.com/questions/4939071/jquery-val-contains)
    have a look there!
    – MISJHA May 02 '13 at 04:14

1 Answers1

1

:contains only looks at the content of elements. input elements have no content. You have to use .filter() [docs] instead:

$('input[name*="new"]').filter(function() {
    return this.value.indexOf('has') > -1;
}).css(...);
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143