Yusaf Khaliq
Yusaf Khaliq

Reputation: 3393

Only apply jquery if the url has a pathname

I recently asked a question

how would you apply this jquery

$(".homeimage").wrap("<a href='" + location.protocol + '//' + location.hostname + "'></a>");

only if the url has a pathname for example http://google.com/search but dont apply the jquery if the url is http:/google.com/

Upvotes: 1

Views: 436

Answers (1)

Ry-
Ry-

Reputation: 224877

if(window.location.pathname && window.location.pathname !== '/') {
    $(".homeimage").wrap("<a href='" + location.protocol + '//' + location.hostname + "'></a>");
}

Upvotes: 1

Related Questions