I have a string
<p attribute="testAttribute">Some text</p>
Anyone know how to do this?
If you use jQuery
var str = '<p attribute="testAttribute">Some text</p>'; var my_obj = $(str); console.info(my_obj.attr('attribute')); // => testAttribute
But don’t use jQuery just to extract the attribute, an alternative is to do it manually (insert the string to the DOM ), and use an identifier for it, but I’m lazy to do that
Or with regex:
var str = '<p attribute="testAttribute">Some text</p>'; alert(str.match(/<p attribute="(\w+)">(.*)<\/p>/));</p>
- Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
- Open a support ticket if you would like specific help with your account, deposits or purchases.
- Item Support by authors is optional and may vary. Please see the Support tab on each item page.
Most of all, enjoy your time here. Thank you for being a valued Envato community member.