Re: Whats the easiest way
Well, the easiest is to use a <div> tag and alter the innerHTML.
Code:
<script type="text/javascript">
var theInteger = 0;
function addToDiv(){
var theDiv = document.getElementById('newContent');
theDiv.innerHTML += 'Testing...' + theInteger + '<br />';
theInteger++;
}
</script>
<input type="button" value="Add to Div" onclick="addToDiv()" />
<div id="newContent"></div>
Re: Whats the easiest way
but if i click on that button three times, will it reproduce the html 3 times or just replace it?
Re: Whats the easiest way
4get it, tested and it works, thanks
Re: Whats the easiest way
You're welcome. Good luck! :wave:
Re: Whats the easiest way
hey, another question. What if the inserted html code is very long... several lines. Ive noticed that the script breaks if I enter html with sveral lines. Is there a way around this?
thanks
Re: Whats the easiest way
The script won't "break" if you are inserting a lot of HTML. You must be writing your strings wrong. Can you post some code?
Re: Whats the easiest way
if i do something like this:
Code:
<script type="text/javascript">
var theInteger = 0;
function addToDiv(){ var theDiv = document.getElementById('newContent');
theDiv.innerHTML += '<div id="scont">
<div class="inner" id="inner">
<div class="innertopleft">
<div class="innertopright">
</div>
<div class="flexcroll" id="flexcroll" onmouseover="javascript:insertRemoveP(false)">
<div id="dynamic">
';
theInteger++;
}
</script>
it wont work, itll give me an error, but if i place all that code on a single line (backspacing it all), it works fine
Code:
<script type="text/javascript">
var theInteger = 0;
function addToDiv(){
var theDiv = document.getElementById('newContent');
theDiv.innerHTML += '<div id="scont"><div class="inner" id="inner"><div class="innertopleft"><div class="innertopright"></div><div class="flexcroll" id="flexcroll" onmouseover="javascript:insertRemoveP(false)"><div id="dynamic">';
theInteger++;
}
</script>
btw, for the html code within, i replace all quotations with \"
Re: Whats the easiest way
Quote:
Originally Posted by Kovo88
it wont work, itll give me an error, but if i place all that code on a single line (backspacing it all), it works fine
That is because you can't have multi-line variables.
You have to do something like...
Code:
theDiv.innerHTML += '<div>';
theDiv.innerHTML += '</div>';
Also, if you are doing this function multiple times, you will have many duplicate IDs for the <div> tags. You will need to use the incrementing variable to make an incrementing ID.