how can you put a user-defined attribute on a html element and then find the element with jquery?
var btn_edit = $('<input class="my_class" userattribute="test" type="button" value="edit" />');
have read about something i CSS where you can do something like this
.my_class[userattribute='test']{
}
You can retrieve it with the
attr()method like this:btn_edit.attr('userattribute')example: http://jsfiddle.net/niklasvh/59SQC/
Note that if you are gonna be using your own custom attributes, you should prepend them with
data-edit
You can find the element which has it set using:
$('*[userattribute]');and get the value of it:
$('*[userattribute]').attr('userattribute')example: http://jsfiddle.net/niklasvh/2n2hb/
and if you want to select the elements with the attribute set to a specific value:
$('*[userattribute="test"]').attr('userattribute')