0

.I use custom form elements on form.

<fieldset>
  <legend id="Cities">Cities</legend>
  <div class="legend-underline"></div>
  <div class="filters" id="Cities-filters">
  <div>
   <span class="checkbox" style="background-position: 0pt -34px;"></span>
   <input type="checkbox" value="Adelaide" class="styled" name="sidecity" id="sidecity-control-name-0">
   <label for="sidecity-control-name-0">Adelaide (58)</label>
  </div>                    
</fieldset>

[Update]

var inputs = $('.filters-widget.bordered div[class!="filters"]');
 inputs.each(function (index, element) { 
$(element).click("click", function () {
 console.log(element); 
});
 }); 

When I click on div the method log() is called twice.

How to solve this problem ?

2
  • 1
    What is so custom about any of these elements, they look pretty standard to me. At what event are you trying to change a checkbox? Commented Feb 6, 2012 at 17:53
  • I've been using custom elements, instead of the standard checkbox there is span class = "checkbox" Commented Feb 7, 2012 at 11:30

3 Answers 3

1

Bind an event handler to the checkbox click event. You can determine whether the checkbox is checked or not by inspecting the checked attribute in your handler:

$('#sidecity-control-name-0').click(function() {
    console.log(this.checked);
});

http://jsfiddle.net/qgR42/

Sign up to request clarification or add additional context in comments.

2 Comments

var inputs = $('.filters-widget.bordered div'); inputs.each(function (index, element) { $(element).click(function () { console.log(element); }); });
var inputs = $('.filters-widget.bordered div[class!="filters"]'); inputs.each(function (index, element) { $(element).click("click", function () { console.log(element); }); }); When I click on div the method log() is called twice
1

You want to create custom elements from markup? Bad Idea. Try enclosing the element into your markup after setting it's css to display:none. Use the element's change event to determine how to show the show your markup element.

That's what jquery UI and Uniform do. Check them out

Comments

1

try .on function after checkboxes are styled

1 Comment

The live method is deprecated as of 1.7, and was not recommended even before that. Please stop suggesting it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.