Solved

javascript button click

Posted on 2015-02-23
1
155 Views
Last Modified: 2015-02-23
I'm transferring this fiddle to a regular html page.

http://jsfiddle.net/cd0meuva/

The fiddle works just fine.

This is my code for my html page but when i click on the buttons on my html page they don't work.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>

    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    

    <style type="text/css">

        .content { display:none; }
        .displayed { display:block; }

    </style>

    <script type="text/javascript">

        $('#buttons button').click(function () {
            $('.displayed').removeClass('displayed');
            var div = $(this).data('div');
            $(div).addClass('displayed');
        });

    </script>



</head>
<body>

<div id="buttons">
   <button data-div="#div1">Button 1</button>
   <button data-div="#div2">Button 2</button>
   <button data-div="#div3">Button 3</button>
</div>

<div class="content" id="div1">This is div 1</div>
<div class="content" id="div2">This is div 2</div>
<div class="content" id="div3">This is div 3</div>

</body>
</html>

Open in new window


My html page buttons should work just like the fiddle above.

Anyone know what i'm doing wrong?
0
Comment
Question by:maqskywalker
1 Comment
 
LVL 29

Accepted Solution

by:
Randy Downs earned 500 total points
Comment Utility
You are missing this:
See my page.

<script type="text/javascript">//<![CDATA[ 
$(function(){
$('#buttons button').click(function() {
    $('.displayed').removeClass('displayed');
    var div = $(this).data('div');
    $(div).addClass('displayed');
});
});//]]>  

</script>

Open in new window

0

Featured Post

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.

Join & Write a Comment

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
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 embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

771 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

11 Experts available now in Live!

Get 1:1 Help Now