When using JQuery, sometimes we need to search for a particular element by an alternate attribute such as it's name, value, or a data attribute. Fortunately this is easy to do. Simple use the syntax $("element[attribute=value]"). You can use any attribute, even the value or type! For example:


$("input[name=first_name]").val("foo");

What about finding an element by a data attribute? You can do that as well. Simply use the syntax $("element[data-attribute=value]"). For example:


 $("input[data-id=12]").val("foo");