Solved

simple jquery issue

Posted on 2013-06-20
7
175 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to dynamically set the form action using jQuery.

707 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

19 Experts available now in Live!

Get 1:1 Help Now