Solved

Need to target a checkbox

Posted on 2012-04-03
2
178 Views
Last Modified: 2012-04-09
I have a click event that sets a checkbox to be checked, however it is targeting all the checkbox on the page with the same class.

I only want to target the checkbox that was clicked. Using Mootools.

var checkEmail = $$('input.user-address');
          $$(".content .addcheck").addEvent('click', function () {
              alert('test');
              checkEmail.set('checked',true);            
          });
0
Comment
Question by:yando18
[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
2 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 37803349
You need to use a unique id for any checkbox that you want to target individually.  Any reference using a class name always targets every member of the class.

Cd&
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 37804240
What about : http://jsfiddle.net/hJbuD/
    $$(".content .addcheck").addEvent('click', function () {
        this.getPrevious('input.user-address').set('checked',true);             
    })¿

Open in new window

0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

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.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

724 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