What Does (function() {})(); Syntax Work?
First question ever here. I'm a bit nervous to break the ice, please be indulgent I just finished the CodeAcademy JS lessons. In the following code that I found to toggle some of m
Solution 1:
fixed
and absolute
are position values not display
functiontoggledisplay(elementID) {
var style = document.getElementById(elementID).style;
style.position = style.position === 'fixed' ? 'absolute' : 'fixed';
};
body {
position: relative;
}
#mydiv {
top: 50px;
left: 80px;
min-height: 100px;
width: 100px;
background-color: lightgrey;
}
<buttononclick="toggledisplay('mydiv')">Toggle</button><divid="mydiv"></div>
Note: There is no real need to have the IIFE function, you can simply use a variable to refer to the style
property
Post a Comment for "What Does (function() {})(); Syntax Work?"