in Education by
I want to make a new span class called "button". When the "button" is clicked, it should run jQuery and flip .front not the "button". I tried: $('.button').bind("click",function() { but it only effects the button, not the .front. HTML: Run! jQuery: $(document).ready(function(){ $('.front').bind("click",function() { // $(this) point to the clicked .front element (caching it in elem for speed): var elem = $(this); // data('flipped') is a flag we set when we flip the element: if(elem.data('flipped')) { // If the element has already been flipped, use the revertFlip method elem.revertFlip(); // Unsetting the flag: elem.data('flipped',false) } else { // Using the flip method defined by the plugin: elem.flip({ direction:'tb', speed: 350, onBefore: function(){ // Insert the contents of the .back div (hidden from view with display:none) // into the clicked .front div before the flipping animation starts: elem.html(elem.siblings('.back').html()); } }); // Setting the flag: elem.data('flipped',true); } }); }); JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You need to attach the event to button, then address the element you wish to manipulate in your function, e.g. $(".button").click(function(){ var elem = $('.front'); … UPDATE: Example of complete page (obviously you would likely put .js and .css in external files, this is just a demo), does this do what you want? If not, why/how not : <!DOCTYPE html> $(document).ready(function() { $(".button").live('click', function() { // $(this) point to the clicked .front element (caching it in elem for speed): var elem = $('.front'); console.log(elem.data('flipped')); // data('flipped') is a flag we set when we flip the element: if (elem.data('flipped')) { // If the element has already been flipped, use the revertFlip method elem.revertFlip(); // Unsetting the flag: elem.data('flipped', false) } else { // Using the flip method defined by the plugin: elem.flip({ direction: 'tb', speed: 350, onBefore: function() { // Insert the contents of the .back div (hidden from view with display:none) // into the clicked .front div before the flipping animation starts: elem.html(elem.siblings('.back').html()); } }); // Setting the flag: elem.data('flipped', true); } }); }); .front { width: 400px; height: 300px; background-color: red; } .back { display: none; } .button { display: block; border: 1px solid black; width: 50px; }
Run!

Hello World!

Run!

I am back

Related questions

0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I want to get this format : 2019-03-24 15:05:20 Here is what I have tried: var today = ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I am trying to redirect to another site then run code on it. function gotonewpage() { window.location. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am trying to redirect to another site then run code on it. function gotonewpage() { window.location. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I am trying to convert string into integer using jquery but it throwing NumberFormatException. How to fix it ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I'm wondering how to stop an animation made with jQuery timers. I think I have tried everything, I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    I have a navigation bar consisting of list items. Right at the end of the nav bar I want a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    Have jquery dialog as closeOnescape as false. want to trigger an event based on esc key press how do ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I found found several question's answers similar to this, I tried some of them, but no luck. May ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I found found several question's answers similar to this, I tried some of them, but no luck. May ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    I am trying to add controls to a simple jquery carousel however I am not sure of how to do that. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 26, 2022 in Education by JackTerrance
0 votes
    I am trying to add controls to a simple jquery carousel however I am not sure of how to do that. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Course Results (${courseResponseList.getCourses().size()}) Want to show above div. jquery script. jQuery. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
...