$ ("#userLevelCss"). attr ("style", "width:78%;float:right;display:none;");
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、 record a way to set/Get properties with JavaScript native code and jquery:
(The article has the full version of the code below)
First, put the JavaScript on.
function attribute () {var val=document. getElementById ("In1"). Value, A1=document. getElementById ("A1"), D2=document.getelementbyid ( "D2") ; The first direct setting itself has its own property method A1.href= "https://www." +val+;//The second set custom property method D2 .setattribute ( "url", "https://www." +val+;//Get the value of the selected property var D1url=d1.getattribute (" url ") Console.log (d1url) ;//Set style D2.style< Span class= "Hljs-preprocessor" >.background= "#FAB2C9" ;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
The results of the operation are as follows:
It's jquery again.
Set properties, Value $ ("#a2"). attr ("href","http://www.w3school.com.cn/");Also set multiple $ ("#a2"). attr ({ "Data-num": "target": "View_window"}); //gets the value of the Select attribute: var a2href=$ ( "#a2"). attr ( "href"), Console.log ( "A2 link address:" +a2href); //set style $ (" #d2 "). CSS (" border ", //simultaneously set multiple $ ( "#d2"). CSS ({ "$", "height": "", " background ": " #E058EA "});
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
The results of the operation are as follows:
The whole piece of code
<! DOCTYPE html><Html><Headlang="EN" ><Metacharset="UTF-8" ><Title></Title><Style> #d1{Width200px;Height50px;}</Style></Head><Body><Div><H3>javascript</H3><InputType="Text"Id="In1"Value="Baidu"/><DivId="D1" ></Div><Ahref="#"Id="A1" > Hyperlinks</A></Div><Hr><Div><H3>jquery</H3><Ahref="#"Id="A2" > Point I Jump</A><DivId="D2" ></Div></Div><Script> functionAttribute() {var Val=document.getelementbyid ("In1"). Value,a1=document.getelementbyid ("A1"), D1=document.getelementbyid ("D1");The first setting itself has its own property method a1.href="Https://www." +val+". com";The second set of custom attribute methods D1.setattribute ("url","Https://www." +val+". com");Gets the value of the selected propertyvar D1url=d1.getattribute ("url"); Console.log (D1url);Set Style d1.style.background="#FAB2C9"; } attribute ();</Script><ScriptSrc="Jquery-1.12.4.min.js" ></Script><Script> Set properties, Value $ ("#a2"). attr ("href","http://www.w3school.com.cn/");Also set multiple $ ("#a2"). attr ({"Data-num":"50","Target":"View_window"});Gets the value of the selection property:var a2href=$ ("#a2"). attr ("href"); Console.log ("A2 link Address:" +a2href); //Set style $ ("#d2"). CSS ("border","5px solid #8E00FF"); //Set multiple $ ("#d2") at the same time. css ({ "width": "$", "height": "$", "background": "#E058EA" }); </script></body></html>
How does jquery set a style for an element?