iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old August 22nd, 2007, 11:34 PM   #1
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,800
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 23rd, 2007, 12:06 AM   #2
Most Reputable Member
 

Join Date: May 2006
Location: North West, UK
Age: 23
Posts: 1,170
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pa007 has a spectacular aura about pa007 has a spectacular aura about
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.
pa007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 23rd, 2007, 12:25 AM   #3
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,800
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: changing function once clicked

yeah
either method will do i guess
How do you do that one?
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.

Last edited by alexgeek; August 23rd, 2007 at 01:11 AM..
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 23rd, 2007, 01:49 PM   #4
New Member
 

Join Date: Jan 2007
Location: Michigan
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 joe3dge is on a distinguished road
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:
<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>
joe3dge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 23rd, 2007, 05:25 PM   #5
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,800
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 25th, 2007, 10:54 PM   #6
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,800
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: changing function once clicked

uh bump?
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 26th, 2007, 08:54 PM   #7
Most Reputable Member
 

Join Date: May 2006
Location: North West, UK
Age: 23
Posts: 1,170
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 pa007 has a spectacular aura about pa007 has a spectacular aura about
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.
pa007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old August 26th, 2007, 09:00 PM   #8
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 16
Posts: 3,800
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: changing function once clicked

Thanks pete
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
alexgeek is offline  
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

Bookmarks

Tags
function


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 HTML, XHTML and CSS 14 December 5th, 2007 09:14 AM
Jump to a new frame when clicked rexusdiablos Flash and ActionScript 8 July 31st, 2007 03:02 PM
Check if user has clicked an adwords ad. Kimochi JavaScript 4 March 4th, 2007 01:31 PM
submit button changes when clicked troublesomegirl JavaScript 0 February 17th, 2007 10:10 PM
Making a rollover stick when clicked map4202003 HTML, XHTML and CSS 4 April 7th, 2004 04:26 AM


Search Engine Optimization by vBSEO 3.2.0 RC8