I have a html like shown bellow. What im trying to achieve is, after I click on a specific div, to get clean number out of that div(id) as a var in a jQuery. Just a number.
PHP is writing html like this.. ability to delete via label id jquery code is even more welcome (so ie. level does not need to be numerated). :s
<div id="level_1">aaa
<label id="del_1">Delete this post</label>
</div>
<div id="level_2">bbb
<label id="del_2">Delete this post</label>
</div>
Something like level_1 (or del_1) to become var num = 1, level_2 (or del_2) to become var num = 2; and so on. You are free to change this html also to obey jQuery if necessary, or just to be more clean. Thx.
This should do the trick.
jsFiddle.
This selects elements of which their
idattribute starts with eitherlevel_ordel_.It then extracts the trailing digits on the
idattribute once clicked.If it could not find any trailing digits,
numwill beundefined.