Add a URL link to a CSS class via JS

Asked

Viewed 232 times

-1

You can add a url link to my CSS class via JS?

Why can’t I edit my HTML file.

I have this CSS to change my logo when it rolls:

.she-header .logo img {
visibility: hidden;
    }

.she-header .logo {
    content:url(https://example.com/Logo2.png) !important;
    margin-left: 30px;
    height: 101px;
    width: 185px;
    }

But when it rolls down I lose the URL link to my home.

Can anyone help me? There’s a way to do this with JS?

  • How so friend you lose link? Has some tag <a> logo wrapped? Does it have any ID by chance or some class just applied to this link? The problem is unclear...

2 answers

1

You can’t really understand what you want. But what I believe is you want to exchange one href one-link...

So you can take the <a> you want for the ID or Classe and exchange the value of href as in the example below.

var a = document.querySelector("a.ouClasse"); 
a.href = "http://link.novo"
<a href="http://link.antigo" id="idDoLink" class="ouClasse">link</a>

0

Via Jquery is as follows:

$(document).ready(function(){
   $(".logo").attr({style: "content:url(https://example.com/Logo2.png)" });
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.