Forum Moderators: open

Message Too Old, No Replies

Back to first div content ?

         

Porsche maniak

8:23 am on Sep 6, 2010 (gmt 0)

10+ Year Member



Hi there !
This is my first post in here,although i am webmaster from 3 years.

Let say i have :

<div id=bla onclick=this.innerHTML='new content'>old content</div>

After the 'bla' is clicked this one must turn back it to 'old content':

<a onclick=? href=javascript:>Back it to old content</a>

When 'old content' is unknown...

JAB Creations

11:02 am on Sep 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld. :)

First off don't use innerHTML, it's horribly unreliable, isn't standard, and will only lead to further aggravation down the road. Instead stick to using W3C DOM syntax.

Also you're not using quotes in your HTML code.

JavaScript
document.getElementById('target_span').firstChild.nodeValue = 'new text';


XHTML
<div><span id="target_span">target text</span></div>


If you are importing (X)HTML via AJAX then use importNode.

- John

Porsche maniak

9:40 am on Sep 7, 2010 (gmt 0)

10+ Year Member



tnx but please read my post again.
It is not that i want.
I want to 'refresh' the div to its first value( or i mean innerHTML ) by clicking a link (or other div).

Fotiman

1:50 pm on Sep 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You could do something like this:

<div id="bla" onclick="this.innerHTML='new content'">old content</div>
<a href="#bla" onclick="document.getElementById('bla').innerHTML='old content'">Revert</a>

Though that requires defining the new content and the old content multiple times, and also relies on inline scripts (which you should generally try to avoid). A better approach, depending on what you're trying to accomplish, might be to have multiple elements (containing all of the "content") and then using JavaScript to control which one is visible. For example:

<div id="bla">old content</div>
<div id="blaNew">new content</div>
<a href="#bla" onclick="toggleBla()">Toggle</a>
<script>
var bla = document.getElementById('bla'),
blaNew = document.getElementById('blaNew'),
oldShown = true;
blaNew.style.display = "none";
function toggleBla() {
if (oldShown) {
bla.style.display = "none";
blaNew.style.display = "block";
}
else {
blaNew.style.display = "none";
bla.style.display = "block";
}
oldShown = !oldShown;
}
</script>


It really depends on what you're trying to do though.

Porsche maniak

3:18 pm on Sep 7, 2010 (gmt 0)

10+ Year Member



Here is the thing i want to do actually.

Posted by someone (onclick the bellow replaces it)
Send PM to someone ?
Yes No

if No is clicked it must return back to 'Posted by someone'
if Yes is clicked it must go to other url.

So i am having problem with the No .
How to back the content to 'Posted by someone' ?

Note : 'someone' is a php variable !


Here is what am i using :

<div id=divboss onclick="this.innerHTML=\'Send PM to '.$entry_array[ 'createdby' ][ 'name'].' ?<br /><a href=pm.php?send='.urlencode($entry_array[ 'createdby' ][ 'name']).'>Yes</a> &nbsp &nbsp <a onclick=? href=javascript:>No</a>\';>'.$entry_array[ 'createdby' ][ 'text'].'</div>

Fotiman

1:20 pm on Sep 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe something like this:

onclick="this.parentNode.innerHTML=\''.$entry_array[ 'createdby' ][ 'text'].'\'"