0
<p>Click the button to add the "mystyle" class to DIV.</p>

<button onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> The classList property is not supported in Internet Explorer 9 and earlier versions.</p>

<p id="myDIV">
I am a DIV element
</p>

<script>

link.href = 'http://resimli.yedek.deniz-tasarim.site/wp-content/themes/deneme.css';

function myFunction() {
  document.getElementById("myDIV").classList.add.link.href;
}

simple question.I want to change color to red after click button.css file is only 1 line

Faruk rıza
  • 68
  • 1
  • 6

1 Answers1

0

That's not how classes or external stylesheets work. What you want to do is link the stylesheet to the page, which makes the classnames and css rules it contains available; then you attach the classname to the element you want styled.

To link the stylesheet that contains the '.mystyle' class definition, include a link to it in the head of your document:

<link rel="stylesheet" href="http://resimli.yedek.deniz-tasarim.site/wp-content/themes/deneme.css">

Then change your script to add the classname, not the url, to the element:

function myFunction() {
  document.getElementById("myDIV").classList.add('mystyle');
}
Daniel Beck
  • 20,653
  • 5
  • 38
  • 53