I Have a function that references a specific input text box. I would like to extend the function to be used by two specific input text boxes. Rather than duplicate the code for the other text box, can anyone advise on how to reference the other?
Here it uses #Tags, but if i wanted it to reference #Tags2 also, how could I do that?
$(function () {
$('#Tags').tagSuggest({
separator: ", ",
tagContainer: 'div',
tags: ["tag1","tag2"]
});
});
To do this just use a comma (a.k.a. the multiple selector), this works for any number of selectors.
There’s a list of all selectors here and a good start-up tutorial you should check out here.
There’s another approach, not needed for your example really, but if you had a lot of elements you wanted to match, or an unknown number, etc…then use a class, like this:
And you can select all elements that have that class using the
.classselector, like this: