How to get the number in the ids

/* ---------- HTML <div id="sites"> <a id="site_1" href="http://siteA.com">siteA</a> <a id="site_2" href="http://siteB.com">siteB</a> <a id="site_3" href="http://siteB.com">siteC</a> ... </div> */ // you need to get 1 from site_1, 2 from site_2 … $("#sites a").click(function(){ var $this = $(this); var nmb = $this.attr('id').match(/site_(\d+)/)[1]; ... });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.