Solved

simple jquery issue

Posted on 2013-06-20
7
179 Views
Last Modified: 2013-06-20
I have a button on a div on my site.
When you click button A, then button B becomes visible by changing the class.

Then when button B has that new class if you click on it, something will happen. right now i'm trying to just log a console .
 
I don't know what I did wrong on the script. I am not getting an error, but no console log either.
I do see the button B has the correct class changed to it.
i tried also doing it with an id.
either one isn't logging anything.

what might be wrong?
  $(".pledgeBut").click(function(){
	  $(".thumbbuttonoff").removeClass('thumbbuttonoff').addClass('thumbbuttonon').attr('id', 'buttonon');
	   });
	  
$(".thumbbuttonon").click(function () {
console.log('button on');
$("#phonescreen1").toggle();
$("#phonescreen2").toggle();
});

$("#buttonon").click(function() {
	console.log("try two");
});

Open in new window

0
Comment
Question by:rivkamak
  • 3
  • 2
  • 2
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39263806
Try this because you set event on non existant element.
For example $("#notYetInThePage").click(function()
will not work

when : $(document).on("click", ".CheckIf_ImPresentInThePage", function() {
will work

  $(".pledgeBut").click(function(){
	  $(".thumbbuttonoff").removeClass('thumbbuttonoff').addClass('thumbbuttonon').attr('id', 'buttonon');
  });
	  
$(document).on("click", ".thumbbuttonon", function () {
    console.log('button on');
    $("#phonescreen1").toggle();
    $("#phonescreen2").toggle();
});

$(document).on("click", "#buttonon", function() {
	console.log("try two");
});

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 39263811
Post the code for the buttons.
0
 

Author Comment

by:rivkamak
ID: 39263863
I posted my code on top . you can see on the top of this page:
http://www.kars4kids.org/texting/index2.asp

Right now the document.on isn't working. it's telling me not a valid function.
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 58

Expert Comment

by:Gary
ID: 39263891
Don't know what we're supposed to be clicking but leakim is probably right anyway.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39263895
Yes because you're using an old jQuery version : 1.6
jQuery.on s available starting jQuery 1.7...

Instead jQuery.on you can use jQuery.live
http://api.jquery.com/live/

  $(".pledgeBut").click(function(){
	  $(".thumbbuttonoff").removeClass('thumbbuttonoff').addClass('thumbbuttonon').attr('id', 'buttonon');
  });
	  
$(".thumbbuttonon").live("click" , function () {
    console.log('button on');
    $("#phonescreen1").toggle();
    $("#phonescreen2").toggle();
});

$("#buttonon").live("click" , function () {
	console.log("try two");
});

Open in new window

0
 

Author Comment

by:rivkamak
ID: 39263896
But why would that happen.
at the time of the click my new id will work.
it's just not there at the time of document.load

How do people do these fancy animations? things happen later as id's and classes change
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39263900
Did you tried my last suggestion ID: 39263895?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question