JQuery select last word after = (equal sign)

I use $(this).attr("href");to select the href attribute value for the clicked element, but I only need to select the part after the last '=' character.

Example:

href = "index.php CON = 123 &? ID = 123 & Sel = heyhey"

I only need the last part of href, which is "heyhey"

How can I choose this?

+3
source share
2 answers

Without regex -

var parts = $(this).attr('href').split('=');
var part = parts[parts.length - 1];
+3
source
var s = "index.php?con=123&id=123&sel=heyhey";
var i = s.lastIndexOf("=");
alert(s.substr(i+1, s.length));

EDIT:

no jQuery required

0
source

Source: https://habr.com/ru/post/1748682/


All Articles