I am attempting to create a custom "struct
" and utilize it in a similar way as I would in another programming language such as Swift. Below is the definition of the "struct":
var myStruct = function (prop1) {
this.prop1 = 30;
}
My attempt to access prop1
looks like this:
var someVar = myStruct.prop1
Unfortunately, this approach does not seem to be working. Can someone please point out what mistake I might be making and suggest a solution?
For reference, here is the link to the JSFiddle, containing the complete code:
$(document).ready(function(){
var myStruct = function (prop1) {
this.prop1 = 30;
}
$("button").click(function(){
$("p").css({"width": myStruct.prop1, "font-size": "200%"});
});
});
<body>
<h2>This is a heading</h2>
<p style="background-color:#ff0000">This is a paragraph.</p>
<p style="background-color:#00ff00">This is a paragraph.</p>
<p style="background-color:#0000ff">This is a paragraph.</p>
<p>This is a paragraph.</p>
<button>Set multiple styles for p</button>