I have a string in JavaScript like #box2
and I just want the 2
from it.
I tried:
var thestring = $(this).attr(\'href\');
var
You can use Underscore String Library as following
var common="#box"
var href="#box1"
_(href).strRight(common)
result will be : 1
See :https://github.com/epeli/underscore.string
DEMO:
http://jsfiddle.net/abdennour/Vyqtt/
HTML Code :
JS Code :
var comm="#box"
$('a').click(function(){
$('div').html(_($(this).attr('href')).strRight(comm))})
if you have suffix as following :
href="box1az"
You can use the next demo :
http://jsfiddle.net/abdennour/Vyqtt/1/
function retrieveNumber(all,prefix,suffix){
var left=_(all).strRight(prefix);
return _(left).strLeft(suffix);
}