if i pass a plain string(i.e height or width) from one function A to B to change a style of an element —
<html>
<script type="text/javascript" >
function B(temp , attributeToChange , val ){
temp.style.attributeToChange = val + "px"
}
function A(){
var to = 200;
B(this , "width" ,400 )
B( this, "height" , to )
}
</script>
<style type="text/css">
.in{
width: 100px;
height: 30px;
}
</style>
<input class="in" type="button" value="Click Me" onclick="A.call(this)">
</html>
This was not possible as i’m not able to use the attributeToChange paramenter obtained as a string in B().Is there a way to achieve this (set the attribute of an elem from a string) or is a workaround to — use switch (attributeToChange)??
Try
In javascript,
a["x"]anda.xmean the same thing.In javascript, we have
someObject, it has an attribute calledwidthand the name of this attribute is calledattributeName. Then,