Solved

simple jquery issue

Posted on 2013-06-20
7
181 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

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