jQuery get numbers only from element id

Say we are storing item ids inside the element container id attributes and we simply want to extract the numbers from the id attribute string. You can get the number from any elements id tag by using a simple JavaScript regular expression replace statement.

$(this).attr('id').replace(/[^d]/g, '');

Before: container1After: 1

Say the id tag contains both letters and numbers and we are interested in getting only the number from the div container id. This could be used for something like when you are trying to grab an id from a parent container element: