Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How JavaScript dynamically creates div properties and styles

Shulou Source: shulou.com Published: 2022-05-31 11:52:41 10月04日 Update

Most people don't understand the knowledge points of this article "How JavaScript dynamically creates div attributes and styles", so Xiaobian summarizes the following contents for everyone. The contents are detailed, the steps are clear, and they have certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "How JavaScript dynamically creates div attributes and styles".

1. Creating div elements:

JavaScript code

functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv[xss_clean]="Testcreateadivelement! "; document.body.appendChild(createDiv); } functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv[xss_clean]="Testcreateadivelement! "; document.body.appendChild(createDiv); }

2. Create div properties:

JavaScript code

functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.title="thisisanewdiv. "; createDiv.id="newDivId"; createDiv.class="newDivClass"; createDiv[xss_clean]="Testcreateadivelement! "; document.body.appendChild(createDiv); } functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.title="thisisanewdiv. "; createDiv.id="newDivId"; createDiv.class="newDivClass"; createDiv[xss_clean]="Testcreateadivelement! "; document.body.appendChild(createDiv); }

3. Create div styles:

JavaScript code

functioncreateElement(){ varcreateDiv=document.createElement("div"); createDiv.style.background="pink"; createDiv.style.border="1pxsolidred"; createDiv.style.width="50px"; createDiv.style.height="50px"; createDiv[xss_clean]="Testcreateadivelement! "; document.body.appendChild(createDiv); } The above is about"JavaScript how to dynamically create div attributes and styles "This article content, I believe everyone has a certain understanding, I hope the content shared by Xiaobian is helpful to everyone, if you want to know more related knowledge content, please pay attention to the industry information channel.

Tags: Content attributes styles dynamics code articles knowledge articles values elements most that is more steps knowledge points industry information information channels channels help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno vpn Xiaomi Apple