Getting the jquery right to do a search in lists and sublists -
I'm having trouble setting up a search input in my taskbar to hide and display elements in my menu. I Want to set a jQuery function which automatically gives the end to my first list and connects to the class ??? Active ?? # Thomas or # Thierry (to see the code) If a string enters the input (#search-bar), then some object exists in the sublist.
Actually my HTML looks like this, anybody thinks how to write scripts?
& lt; Script type = "javascript" & gt; Var str; Function search () {str = $ ('# search-bar'). Text (); AddClass ("active");}; & Lt; / Script & gt; & Lt; Input id = "search-bar" type = "article" name = "search" placeholder = "rechercher" class = "form-control geo-search-sidebar" /> & Lt; UL & gt; & Lt; Li id = "thomas" & gt; & Lt; Span class = "title" & gt; Thomas & lt; / Span & gt; & Lt; Ul class = "sub menu" & gt; Lee ID = "red" & gt; & Lt; Span class = "title" & gt; Red & lt; / Span & gt; & Lt; / Li & gt; & Lt; Li id = "orange" & gt; & Lt; Span class = "title" & gt; Orange & lt; / Span & gt; & Lt; / Li & gt; & Lt; Li id = "green" & gt; & Lt; Span class = "title" & gt; Green & lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Li class = "start" id = "theory" & gt; & Lt; Span class = "title" & gt; Theory & lt; / Span & gt; & Lt; Ul class = "sub-menu" & gt; Lee ID = "Blue" & gt; & Lt; Span class = "title" & gt; Blue & lt; / Span & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Li & gt; & Lt; / Ul & gt; You did not find the input value like this $ ('# search- Bar '). Text () ; Should be changed to $ ('# search-bar'). V Al () ; str = $ ('# search-bar'). Text (); // change val (); $ ("Ul li :: (straw) included) addClass (" active "); ^^^^ You did not get a text value, in fact you are searching the string" str " < P> Change ("+ Str +") for AddClass ("active") var str = $ ('# search-bar'). Val (); $ ( "Ul li:; Trying to use the input is like this mouseup event
$ ('# search-bar'). ("Input", function () {var str = this.value.trim (); $ ("ul li: occurs (" + str + "). AddClass (" active ");});
Comments
Post a Comment