cleverpaul
cleverpaul

Reputation: 945

Is the HTML .style property fully compatible with Safari browser?

Consider the following Javascript command:

document.getElementsByClassName('phone_label')[0].style = 'color:#ec5840';

This works fine in Firefox and Chrome, but not in Safari.

This article on the .style property does not indicate any issues with Safari. https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

Is the HTML .style property fully compatible with Safari browser? (Both desktop and iOS versions).

  
  function changecolor() {
    document.getElementsByClassName('phone_label')[0].style = 'color:#ec5840';
    alert('The phone number should change to red!');  
  }
  <p class='phone_label'>0411 111 111</p><br>
  <button onclick='changecolor()'>Click</button>

Upvotes: 0

Views: 503

Answers (1)

Jon Uleis
Jon Uleis

Reputation: 18669

Per the MDN on HTMLElement.style, here are suggestions for the correct syntax:

document.getElementsByClassName('phone_label')[0].style.cssText = 'color: #ec5840;';

document.getElementsByClassName('phone_label')[0].style.color = '#ec5840';

Upvotes: 1

Related Questions