I have this tag in example:
<button onclick="setLocation('http://mysite.com/checkout/cart/add/product/17/')" />
What I need to do is initiate ajax request on button click. I need URL segment "product/17" from above appended to my ajax url. Any clever ways to extract this without using regex? HTML is not changable - however I can modify the URL, and in that case I would need to extract the exact URL from onclick attribute.
So I either need URL or "product/17" extracted from onclick attribute, hopefully without using regex.
Thanks
So, if no RegExp usage, and no criteria for parsing the string, here is the simplest solution:
var str = $("button").attr("onclick");
str = str.substring(str.lastIndexOf("add/") + 4, str.length - 3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With