I have domain name for eq.
1) http://www.abc.com/search 2) http://go.abc.com/work
I get only domain name from the above URL
Output
While pure JavaScript is sufficient here, I still prefer the jQuery approach. After all, the ask was to get the hostname using jQuery.
var hostName = $(location).attr('hostname'); // www.example.com