Home
Web Front-end
JS Tutorial
Native js implements the result of changing the name and value of the div attribute style at will_javascript skills



Native js implements the result of changing the name and value of the div attribute style at will_javascript skills
Some simple examples use native js and jQuery to change div attributes and reset them at will. The code is as follows:
Copy code The code is as follows:
Enter "attribute name" in the upper input box and "Attribute Value", click the OK button to view the effect.
$(function(){
$("button:first").click(function() {
var styleName= $("#outer").find("input:first").val();
var styleVal = $("#outer").find("input:last") .val();
$("#div1").css(styleName,styleVal);
})
$("button:last").click(function(){
$ ("#div1").removeAttr("style");
})
})
< ;body>
Enter "attribute name" and "attribute value" in the upper input box, and click the OK button to view the effect.