JSFiddle - React, Tailwind, and code Playground

by 1eddy87

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div>
  <p>
    I need to get the end part of the URL(john)
  </p>
</div>

<a href="https://www.blah.com/john">click here</a>

JavaScript

$('a[href]').click( function(e) {
	
  e.preventDefault();
  
  var test = this;
  
  // works fine
  alert(test)
  
  // doesn't work
  alert(test.substring(test.lastIndexOf('/') + 1));
  
})

/*
var x = "jdhsajd/sadsa/sadas/data";
alert(x.substring(x.lastIndexOf('/') + 1));
*/