Ik heb een scriptje van een site en als je dan op wat text double-clickt de div een textbox word. Maar hoe zorg ik er nou voor dat als je naast de textbox klikt, de textbox weer een divje word?
Script:
<? //Dit alleen voor het kleurtje :)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Switchende dinges</title>
<script language="javascript" type="text/javascript">
text = new Array(); //This array will hold variables to tell the script the state that it should switch to
function switchState(id)
{
content = ''; //Nullify the content variable
if( text[id] != 1 ) //Check if text['id'] is set to 1 (explained later)
{
content = document.getElementById('child' + id).innerHTML; //Define content as the inner content of the div
new_html = '<input type="text" id="child' + id + '" value="' + content + '" />'; //Define the new HTML (textbox)
document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
text[id] = 1; //We set this variable for the script to remember that we already set it to a text box
}
else
{
//So with this case we will be doing the opposite and switching back to a div
content = document.getElementById('child' + id).value; //Define content as the value of the textbox
new_html = '<div id="child' + id + '">' + content + '</div>'; //Define the new HTML (div)
document.getElementById('parent' + id).innerHTML = new_html; //Set the parent div's HTML to the new HTML
text[id] = 0; //We set this variable for the script to remember that we have set it back to a div
}
}
</script>
</head>
<body>
<div id="parent1" ondblclick="javascript:switchState(1)">
<div id="child1">Some text</div>
</div>
<div id="parent2" ondblclick="javascript:switchState(2)">
<div id="child2">Some more text</div>
</div>
</body>
</html>
?>//Afsluiten van het kleurtje
Iemand een idee?
Ik hoop dat jullie nog steeds weten dat ik nr 1 noob ben in JS