Используйте .filter()
для фильтрации селектора jquery и добавления к ним прослушивателя событий.
var names = ["name1", "name2"];
$("input").filter(function(){
return names.indexOf($(this).attr("name")) != -1;
}).on("mouseenter", function() {
$(this).attr('title', 'This is the hover-over text');
});
var names = ["name1", "name2"];
$("input").filter(function(){
return names.indexOf($(this).attr("name")) != -1;
}).on("mouseenter", function() {
$(this).attr('title', 'This is the hover-over text');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="name1" value="name1">
<input type="text" name="name2" value="name2">
<input type="text" name="name3" value="name3">
Также вы можете добавить прослушиватель событий ко всем входам и в функции обратного вызова проверить его имя.
var names = ["name1", "name2"];
$("input").on("mouseenter", function() {
if (names.indexOf($(this).attr("name")) != -1){
$(this).attr('title', 'This is the hover-over text');
}
});
var names = ["name1", "name2"];
$("input").on("mouseenter", function() {
if (names.indexOf($(this).attr("name")) != -1){
$(this).attr('title', 'This is the hover-over text');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="name1" value="name1">
<input type="text" name="name2" value="name2">
<input type="text" name="name3" value="name3">