Solved

simple jquery issue

Posted on 2013-06-20
7
177 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
DevOps Toolchain Recommendations

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

 
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

Suggested Solutions

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now