changing function once clicked

This is a discussion on "changing function once clicked" within the JavaScript Forum section. This forum, and the thread "changing function once clicked are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 23rd, 2007, 02:34
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Question changing function once clicked

Okay, say I have a header:
<h1 class="header" id="myHeader" onclick="myfunction()">header</h1>
that calls this function:
function myFunction()
{
var x=document.getElementById("remove_div");
x.parentNode.removeChild(x);
}

Is there a way to change the header to this:
<h1 class="header" id="myHeader" onclick="myfunction2()">header</h1>
after it's been clicked?
Thanks guys, I only just learnt javascript so bare with me
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 23rd, 2007, 03:06
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: changing function once clicked

RE you trying to remove the div onclick and then replace it when it's clicked again? There is probably an easier way to do this.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 23rd, 2007, 03:25
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: changing function once clicked

yeah
either method will do i guess
How do you do that one?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)

Last edited by alexgeek; Aug 23rd, 2007 at 04:11.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 23rd, 2007, 16:49
Junior Member
Join Date: Jan 2007
Location: Michigan
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: changing function once clicked

if you add a third function and a variable to test wheather you clicked on the headr, then you wont have to change any html.

like this:

Code: Select all
<script language=javascript>
 
function myFunction(){
/*do something on the first click*/
}
 
function myFunction2(){
/*do something on the second click and any following clicks*/
}
 
var isClicked = 0; //variable to test wheather you clicked the header.
                        //initialy at false
 
function onClickFunction(){
  if(!isClicked){//when you fist click the header isClicked is set to false so it exicutes the first function and sets is clicked to true
    isClicked = 1;
    myFunction();
  }
  else{//any other time you click it, is clicked is set to trues so it exicutes the second function
    myFunction2();
  }
}
 
</script>
 
<h1 class="header" id="myHeader" onclick="onClickFunction()">
header
</h1>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 23rd, 2007, 20:25
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: changing function once clicked

thank for that
also,
since:
var x=document.getElementById("remove_div");
x.parentNode.removeChild(x);
removes the div
how to i put it back in?
I don't want to use visiblity, as it just hides it and the space is still taken up
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 26th, 2007, 01:54
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: changing function once clicked

uh bump?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 26th, 2007, 23:54
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: changing function once clicked

If you change it too display none it actually takes it out of the document flow so that would be your best bet. You don't really want to be removing and re-writing the div into the code, that wouldn't be very efficient. You can either change the style attribute of that element or change the class name (you would have to have the alternative style set up in the css of course).

Hope that helps a bit.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 27th, 2007, 00:00
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: changing function once clicked

Thanks pete
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
function

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Image links disappear after clicked finalfantasyfanatic Web Page Design 14 Dec 5th, 2007 12:14
Jump to a new frame when clicked rexusdiablos Flash & Multimedia Forum 8 Jul 31st, 2007 18:02
Check if user has clicked an adwords ad. Kimochi JavaScript Forum 4 Mar 4th, 2007 16:31
submit button changes when clicked troublesomegirl JavaScript Forum 0 Feb 18th, 2007 01:10
Making a rollover stick when clicked map4202003 Web Page Design 4 Apr 7th, 2004 07:26


All times are GMT. The time now is 22:29.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42