Home
Web Front-end
JS Tutorial
jQuery implements arbitrarily changing the name and value of any attribute of a div (partial native js implementation)_javascript skills



jQuery implements arbitrarily changing the name and value of any attribute of a div (partial native js implementation)_javascript skills
div
style attribute
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:
< input type="text" value="background" name="styleName" />
Enter "Attribute Name" and "Attribute Value" in the upper input box, click the OK button See 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");
})
})
p>
Enter "attribute name" and "attribute value" in the upper input box, and click the OK button to view the effect.