js modify tag content style

Use js to modify its style:

<div id = "name"></div>

let a = document.getElementById("name");
a.style.width = "10px";// 修改

JS gets/modifies the content value entered in the text box:

<input id="cons" type="text">

var a = document.getElementById("cons").value;//获取
document.getElementById("cons").value = 123;//修改

Modify the content in the div tag: innerHTML, innerText: 

document.getElementById("name").innerHTML = 123;
document.getElementById("name").innerText = 123;

Difference: The innerHTML attribute will output the attribute value to the browser in the form of html code, which means that html code can be passed within innerHTML. The innerText attribute outputs the attribute value to the browser in plain text.

Modify tag content style in Html5:

<div class="item" οnclick="setContData('Country')">Click to modify data</div>

<img id="khalimg1" src="images/blog/Picture3.png" alt="">

<h5 id="khaltext1">Shaanxi Huashan</h5>

<script>
    function setContData(val) {
      if (val == "乡村") {
        document.getElementById('khalimg1').src = "images/blog/图片1.png"
        $("#khaltext1").html("杭州萧山")
      }
    }
</script>

Guess you like

Origin blog.csdn.net/cdd9527/article/details/128131486