Thread: <br /> toevoegen door js
-
29-09-2009, 22:07 #1Member
- Registered
- 21/04/09
- Location
- zwevegem
- Posts
- 367
- iTrader
- 7 (89%)
- Mentioned
- 0 Post(s)
- Reputation
- 0/2
<br /> toevoegen door js
Dit is mijn huidig script
als ik op de knop add input klik, krijg ik dus 2 extra inputvelden met hun unieke waarden.Code:<input id="button" type="button" value="add input" /><br /><br /> <div id="inputs"></div> <script type="text/javascript"> var target = document.getElementById("inputs"), count = 1, count2 = 1, addInput = function() { var input = document.createElement("input"); input.setAttribute("name", "artikel"+count); input.setAttribute("id", "artikel"+count); input.setAttribute("value", "artikel"+count); input.setAttribute("size", 30); input.className = "foo"; target.appendChild(input); count++; var input = document.createElement("input"); input.setAttribute("name", "prijs"+count2); input.setAttribute("id", "prijs"+count2); input.setAttribute("value", "prijs"+count2); input.setAttribute("size", 30); input.className = "foo"; target.appendChild(input); count2++; }; document.getElementById("button").onclick = addInput; </script>
maar ik had graag een <br /> erna gekregen.
ik ben een totale leek op vlak van javascript, ik heb nu al tijdje zitten googlen maar niets gevonden dat werkt.
document.createElement('br'); heb ik al overal proberen te plaatsen, maar niets dat het doet lukken.

thx,
Lorenzono votes
-
-
29-09-2009, 22:13 #2Approved 9-lifer
- Registered
- 06/12/06
- Location
- Tongeren
- Posts
- 1,880
- iTrader
- 26 (100%)
- Mentioned
- 0 Post(s)
Je kan html toevoegen door:
dus voor jou:Code:document.write('<p>This is a paragraph</p>');
Code:document.write('<br />');PSN:SpectreX15
What doesn't kill me makes me stronger. What does kill me, I'll deal with when I respawn.
I am root. If you see me laughing, you better have a backup!no votes
-
29-09-2009, 22:22 #3Member
- Registered
- 21/04/09
- Location
- zwevegem
- Posts
- 367
- iTrader
- 7 (89%)
- Mentioned
- 0 Post(s)
- Reputation
- 0/2
die had ik ook al ergens gevonden,
maar als ik dat in mijn functie laat uitvoeren krijg ik een blanco pagina als ik op add input klik.
En als ik het voor of na
plaats, doet het ook niets.document.getElementById("button").onclick = addInput;
tog bedankt voor uw hulp
no votes
-
30-09-2009, 08:37 #4Approved 9liver
- Registered
- 28/11/03
- Location
- Drongen
- Posts
- 6,665
- iTrader
- 5 (100%)
- Mentioned
- 0 Post(s)
- Reputation
- 6/28
Voor (of erna gezien ge begint met er eentje toe te voegen)
target.appendChild(input);
doet ge
target.innerHTML += "<br/>";no votes
-
30-09-2009, 11:38 #5Member
- Registered
- 21/04/09
- Location
- zwevegem
- Posts
- 367
- iTrader
- 7 (89%)
- Mentioned
- 0 Post(s)
- Reputation
- 0/2
no votes
-
30-09-2009, 12:22 #6
Beter zou zijn om aan uwe laatste input een margin te geven.
input.style.marginBottom = "10px";
of met jQuery
$("input#id").css("margin-bottom","10px");no votes
-
30-09-2009, 12:24 #7Approved 9liver
- Registered
- 28/11/03
- Location
- Drongen
- Posts
- 6,665
- iTrader
- 5 (100%)
- Mentioned
- 0 Post(s)
- Reputation
- 6/28
input fields worden toch standaard als inline beschouwd dus de margin-bottom zal toch niets uitmaken?
je moet dan ook de display = "block" zetten of niet?
dan kan je dat idd doen zonder br.no votes
-
30-09-2009, 16:55 #8
Goe opgemerkt!
Verbetering:
Beter zou zijn om aan uwe laatste input een margin te geven.
input.style.display = "block";
input.style.marginBottom = "10px";
of met jQuery
$("input#id").css("display","block");
$("input#id").css("margin-bottom","10px");
is uiteindelijk meer code dan innerHTML , maar volgens mij is da een beetje deprecatedno votes

