Get ID from URL with jQuery

Viewed 136597

I've got a url like this:

http://www.site.com/234234234

I need to grab the Id after /, so in this case 234234234

How can i do this easily?

11 Answers

You could just use window.location.hash to grab the id.

var id = window.location.hash;

I don't think you will need that much code to achieve this.

const url = "http://www.example.com/1234"
const id = url.split('/').pop();

Try this, it is much easier

The output gives 1234

Try this

var url = "http://www.exmple.com/234234234"
var res = url.split("/").pop();
alert(res);
Related