jquery get number from id
how can i get the number from a div tag's id? example: <div id="button1"></div> how can i get the 1 and store it in a variable? var id = $("div").attr('id').replace(/button/, ''); Your "id" values cannot be purely numeric; they need to start with a letter or "_" like an identifier. ( Note : that's not true in HTML5 documents.) Once you've got a number in your "id" value like that, you would just use the jQuery attr() function to get the id: var theId = parseInt($('div.whatever').attr('id').replace(/[^\d]/g, ''), 10); // replace all non-digits with nothing alert($('div').attr("id").replace(/\D