Ich versuche, eine Liste zu machen. Wenn ich auf jedes Element in der Liste klicke, wird eine Beschreibung angezeigt. Im Moment zeigt mein Code nur die Elemente an, und wenn ich auf ein Element klicke, werden Beschreibungen aller Elemente angezeigt. Kann mir jemand helfen, dieses Problem zu beheben?Javascript onclick für mehr Info
<script type="text/javascript">
function moreInfo(){
var para= document.createElement("p")
var divObj = document.getElementById("p1");
divObj.appendChild(para);
var divObj = document.getElementById("p2");
divObj.appendChild(para);
var divObj = document.getElementById("p3");
divObj.appendChild(para);
var divObj = document.getElementById("p4");
divObj.appendChild(para);
var txt = document.createTextNode("This product is good");
para.appendChild(txt);
var txt = document.createTextNode("This product is bad");
para.appendChild(txt);
var txt = document.createTextNode("This product is pretty");
para.appendChild(txt);
var txt = document.createTextNode("This product is ugly");
para.appendChild(txt);
}
</script>
</head>
<body>
<div id="p1" class="divStyle">
<p onclick="moreInfo()">
Good
</p>
<div id="p2" class="divStyle">
<p onclick="moreInfo()">
Bad
</p>
<div id="p3" class="divStyle">
<p onclick="moreInfo()">
Pretty
</p>
<div id="p4" class="divStyle">
<p onclick="moreInfo()">
Ugly
</p>
</div>
Vielen Dank !!! – shyn