I find this selector format cumbersome if I need to use it often:
$('[name="someElementName"]').val()
I thought about extending jQuery so that I can use a format like this:
$('@someElementName').val()
I understand that jQuery is just following the convention of CSS and that I am breaking convention.
Regarding the choice of “@”, I just picked a special character that seemed unused for selectors and not likely to create a conflict. If anyone has a better suggestion I’m open to suggestions.
I don’t have the option to not use the name attribute as part of the selector.
I was thinking about using regular expression like this:
selectorString.replace(/\@([\d\w\s\-]*)/g, '[name="$1"]')
From here I am stuck as how to extend jQuery to utilize that regex in such a way that I can use code like “$(‘@someElementName’).val();
How about this:
usage:
See http://jsfiddle.net/alnitak/n6nEW/