i have the following code in html, js and css.
<html>
<head>
<script type="text/javascript">
function add() {
for(var j=0;j<4;j++){
var i = document.getElementById( 'old' );
var d = document.createElement( 'div' );
d.id = "new1";
d.innerHTML = i.innerHTML ;
var p = document.getElementById('new');
p.appendChild(d);
}
}
</script>
</head>
<body>
<div id="old" style="visibility:hidden;">
<select>
<option value="pls">Please</option>
<option value="1"><</option>
<option value="2">></option>
<option value="3">=</option>
</select>
<input type="text" value=""/>
</div>
<hr/>
<div id="new" style="visibility:hidden;">
<input type="button" value="go"/>
</div>
<hr/>
<button onclick="add();">Add</button><br>
</body>
</html>
Here i am trying to display dynamic div on click of add button. it is adding simply, but the div is visible by default, so i am hiding it through css style=” hidden”. now on click of add button it is adding but the div is hidden.
Here i am facing a problem how to show the div (here looping i.e 4).
And the go button will come below of it.
Also I am using css like ternary operator. e.g.
el.style.visibility = (el.style.visibility == “hidden”) ? “visible” : “hidden”;
I am really puzzled what you are trying to achieve. You should either create the new div like this
Or you should make the div visible on the first click. Add to your function this
You can see this http://jsfiddle.net/tkKun/ for the former example