0

my code-

$("#search").keyup(function(){
    var $search = $("#search");
    $("#l").find( $search ).css('color','red');
});

$("#l") is the div I want to search in.

Reporter
  • 3,897
  • 5
  • 33
  • 47
Yash Mathur
  • 69
  • 1
  • 5

2 Answers2

1
$("#search").keyup(function(){
    var $search = $("#search");
    $("#l").children().find('#'+$search.val()).css('color','red');
});
Mark Perry
  • 1,705
  • 10
  • 12
  • but my "#search" textbox isn't in the "#l" div, please help – Yash Mathur Jul 11 '11 at 10:07
  • It doesn't need to be. The query just says take the input from the `#search` textbox and try to match an element with the id of what the user has typed in the `#l` list. – Mark Perry Jul 11 '11 at 10:18
  • Added `.children()` so it searches the lists children instead of the list itself. (Guessing here that `#l` refers to a `
      ` element.
    – Mark Perry Jul 11 '11 at 10:19
  • So you want to highlight the text in the div in red right? If so check this answer: http://stackoverflow.com/questions/1230714/jquery-how-to-highlight-certain-words-with-jquery – Mark Perry Jul 11 '11 at 10:28
0
$("#search").keyup(function(){

    var searchTerm = "Hello";
    $("#l:contains('+ searchTerm +')").css('color','red');
});

Just use :contains('value') selector http://api.jquery.com/contains-selector/#text

Find text string using jQuery?

Community
  • 1
  • 1
Ahmed Magdy
  • 5,956
  • 8
  • 43
  • 75