jonagoldman
jonagoldman

Reputation: 8754

jQuery select last word after = (equal symbol)

I'm using $(this).attr("href"); to select the href attribute value of the clicked element, but I need to select only the part after the last '=' symbol.

Example:

href="index.php?con=123&id=123&sel=heyhey"

I only need the last part of the href that is 'heyhey'

How can I select this??

Upvotes: 3

Views: 1509

Answers (2)

Im0rtality
Im0rtality

Reputation: 3533

var s = "index.php?con=123&id=123&sel=heyhey";
var i = s.lastIndexOf("=");
alert(s.substr(i+1, s.length));

EDIT:

doesn't even need of jQuery

Upvotes: 0

Eran Galperin
Eran Galperin

Reputation: 86805

Without regex -

var parts = $(this).attr('href').split('=');
var part = parts[parts.length - 1];

Upvotes: 3

Related Questions