substr - How to get a certain sub_string in a sting using jquery -
i have routine produces id attributes on tag -- anywhere [1] [??]
i want able evaluate string , extract id ordinal using jquery.
here sample markup:
<div id="abc[1]"></div> <div id="abc[15]"></div>
i know can this:
var n1=???.indexof("["); var n2=???.indexof("]"); var theid = $('#???').substr(n1,n2);
but wondering how make work possible.
i want theid
retrieve 1
or 15
, etc.
try string.replace()
var n = $(el).attr('id'); var theid = n.replace('abc[', '').replace(']', '');
Comments
Post a Comment