I am dynamically generating a dropdown list on the page when a user loads it. I’d like to get the value of the dropdown using jquery or javascript.
The tricky part is that the dropdown will have a value as such:
“I love Rabbits ($19.95)”
I want to get the value of the dropdown and then isolate the value inside of the brackets.
Any ideas?
Cheers!
Getting the value is easy, use
val(). That will be a string.Then you just grab the value with a regex, probably with a capture group; for instance:
That regex says: “Find a
(and then capture everything following it that isn’t a)“. Then we take the value of the capture group.