Solved

CheckBox inside a DIV

Posted on 2011-03-06
2
491 Views
Last Modified: 2013-11-05
I have a simple div that has 2 checkboxes inside. therefore when I select a checkbox inside the div I want to call a function and do something. ie.

<div id='wheels'>
    <asp:CheckBox ID="hotwheels" CssClass='WheelsCSS' Text="HOT" runat="server"/>
    <asp:CheckBox ID="Littlewheels" CssClass='WheelsCSS' Text="LITTLE" runat="server"/>
</div>

//Never gets fired but no syntax error I'm I missing something?
$('#wheels > input.checkbox').click(function () {
         //do something                
            });
0
Comment
Question by:7of9121098
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 50 total points
ID: 35049699
You may use :

        $('#wheels').find("input[type='checkbox']").click(function () {
            alert("you click " + $(this).attr("ID"));
        });

Open in new window


Test page :



<%@ Page Title="Page d'accueil" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $('#wheels').find("input[type='checkbox']").click(function () {
            alert("you click " + $(this).attr("id"));
        });
    });
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div id='wheels'>
    <asp:CheckBox ID="hotwheels" CssClass='WheelsCSS' Text="HOT" runat="server"/>
    <asp:CheckBox ID="Littlewheels" CssClass='WheelsCSS' Text="LITTLE" runat="server"/>
</div>
</asp:Content>

Open in new window

0
 

Author Closing Comment

by:7of9121098
ID: 35053263
Excellent! Thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Building a successful professional career is a long and difficult journey, especially in case if your decisions are not chosen carefully. For example, if you think that you can get to the desired position without experience and apply for it, your ch…
Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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