I have the following url.
http://127.0.0.1/ci/index.php/admin/menus/edit/24
I want to get 24 from this to use in jquery/javascript.
Something like this.
var id=this.href.replace(/.*=/,'');
this.id='delete_link_'+id;
Could anyone tell me how to code this?
I have the following url.
http://127.0.0.1/ci/index.php/admin/menus/edit/24
I want to get 24 from this to use in jquery/javascript.
Something like this.
var id=this.href.replace(/.*=/,'');
this.id='delete_link_'+id;
Could anyone tell me how to code this?
Share Improve this question asked Dec 11, 2009 at 20:23 shinshin 32.7k71 gold badges193 silver badges272 bronze badges 1- See stackoverflow./questions/1788908/… (also, this is a duplicate of that one question). – Crescent Fresh Commented Dec 11, 2009 at 21:04
4 Answers
Reset to default 5var id = this.href.match(/[^\/]*$/)
this.id = 'delete_link_' + id;
Why use regex?
var parts=this.href.split("/");
var id = parts[parts.length - 1];
this.id='delete_link_'+id;
Regex is overkill here.
var s = "http://127.0.0.1/ci/index.php/admin/menus/edit/24";
s.substring(s.lastIndexOf("/")+1);
"http://127.0.0.1/ci/index.php/admin/menus/edit/24".match(/^.*\/([^\/]+)$/)[1]