I have some anchor elements with some text, like "cat", "cow", "dog"
For example, when I click on "cat" I want to add text to the search input.
I have tried to:
jQuery ('.link') .on ('click', function (event) {jQuery ('input [name = "Search"] '). Val (jQuery ('. Link '). Text (). Trim ()); jQuery (' input [name = "search"] ') .keyp ();});
But I need to listen to each anchor element and update search input accordingly, it just works once.
Any suggestions?
Instead of adding text to elements that click, the problem is due to your selector within the click function In the search box, you are writing the texts of all the elements in the search box sequentially, so that only the last .link
text remains in the search box. Try it instead:
jQuery ('.link') .on ('click', function) {jQuery ('input [name = "search"]'). Val ($ (This) .text () .trim ()); jQuery ('input [name = "search"]') .keyp ();});
It's the one, see if it's what you wanted.
No comments:
Post a Comment