javascript - Passing value from one input to keyup function using .filter -


i trying filter form value change links color , background incorrect

$("a").filter('a[href$='"'+username'"]').css("background-color", "#ff0000");    

here html example

 <body>     <div class="main">      <p>      lorem ipsum dummy text of printing , typesetting industry.     <a href="u=3153">user1</a>, <a href="u=31532">user2</a>, <a href="u=231532">user3</a>, <a href="u=11111">user4</a>, <a href="u=22222">user5</a>.     </p>      </div>     <div id="buttons">     <form method="post" action="">     username:<br />      <input type="text" value="" class="userform"  id="user" maxlength="15"/>     <br />     <input type="submit" value="   submit   "  class="submit"/>     </div>     </body>    

and jquery

$(document).ready(function(){     $("body").keyup(function()      {     var username = $("#user").val();     $("a").filter('a[href$='"'+username'"]').css("background-color", "#ff0000");     });     }); 

my problem can't "put" form value in keyup function

you have syntax error in selector, try this:

 $("a").filter('a[href$="'+username+'"]').css("background-color", "#ff0000");             //('a[href$='"'+username'"]')                                        //     ^           ^ 

example: http://jsfiddle.net/niklasvh/lm6ge/


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -