To apply styling properties using JavaScript, use the same property name as you would in CSS, but without the hyphen and with camel casing, against the 'style' object. For example, instead of using 'font-size' in CSS, you would use 'fontSize' when applying it to elements via JavaScript. One thing to keep in mind is that certain properties like 'font-size' are inherited, meaning they will affect descendant elements as well. So, you can apply the style to a parent element instead of each individual child element to avoid affecting unnecessary elements. However, if you do apply it to a parent element, all descendant elements will be affected and you may need to reset the styles on elements you don't want to change.
document.querySelector("button").addEventListener("click", function(){
var iw = window.innerWidth;
document.getElementById("outputArea").textContent = "The usable width of the page is: " + iw + "px";
if(iw > 400){
var a = document.querySelectorAll("#leftcol > a");
for(var i = 0; i < a.length; i++){
a[i].style.fontSize = "3em";
}
}
});
<div id="outputArea"></div>
<div id="leftcol">
<a href="">1</a><br>
<a href="">2</a><br>
<a href="">3</a><br>
<a href="">4</a><br>
<a href="">5</a><br>
<a href="">6</a><br>
</div>
<button>Click Me</button>
Furthermore, it's recommended to avoid using 'document.write()' in JavaScript unless you are dynamically creating an entire DOM structure. Instead, consider injecting content into existing DOM elements for better practice.