Alright, so I have an HTML element as <div id="slide_item_#"> where # is a number. What I would like to do, using Javascript, is get the number from the id. So I would assume a regular expression, I just don’t know how to use them in Javascript.
var html_id = "slide_item_3";
var id_number = /* code here so that id_number == 3 */ ;
I would just parse the string without the prefix using
parseInt(), like this:An improvement, if you have the option, would involve naming your classes for your element the same as your id (i.e., “slide_item”), except that your id would have the correct number appended to the end (i.e., “slide_item2”). Then, in your code, you would simply use
this.classNameinstead of explicitly using ‘slide_item_’, and the rest of this code would be more dynamic