Forums › Forums › Search & Filter Pro › Add "Checked" in Input Attributes
- This topic has 3 replies, 2 voices, and was last updated 9 years, 5 months ago by Ross.
-
Ross Moderator(Private) June 1, 2015 at 11:57 am #18601
Hi Zheng,
I believe your browser already does this by default?
Thanks
Anonymous(Private) June 6, 2015 at 4:09 pm #19003hello Ross,
just when I use firebug, I cannot see checked=”checked” within the <input> tag?
I wrote a piece of JQuery code to change the default style as below, but it doesn’t add checked=”checked” to <input> and “checkedbox” class to <span> either as it is supposed to, do you have any idea why?
my code:
$(‘input:checkbox’).hide().each(function() {
$(this).attr(‘data-check-fx’, this.value);
var label = $(“label[for=” + ‘”‘ + this.id + ‘”‘ + “]”).text();
$(‘‘+'<span class=”checkbox’ + (this.checked ? ‘ checkbox-checked’ : ”) + ‘”></span>‘).insertAfter(this);
});$(‘sf-field-tag label’).on(‘click’, function(e) {
e.preventDefault();
if($(this).find(‘input:checkbox’).is(‘:checked’)) return;
var unique = $(this).find(‘a.check-fx’).attr(‘data-check-fx’);
$(“sf-field-tag label a[data-check-fx='”+unique+”‘] span”).attr(‘class’,’checkbox’);
$(“sf-field-tag label input:checkbox[data-check-fx='”+unique+”‘]”).attr(‘checked’,false);
$(this).find(‘a.check-fx’).find(‘span’).attr(‘class’,’checkbox-checked’);
$(this).find(‘input:checkbox’).attr(‘checked’,true);
}).on(‘keydown’, function(e) {
if ((e.keyCode ? e.keyCode : e.which) == 32) {
$(this).trigger(‘click’);
}
});Thanks!
EmmaRoss Moderator(Private) June 8, 2015 at 1:38 pm #19059Hi Emma
I’m not sure what you are trying to achieve?
If you take a look here:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_checkbox
And use firebug to inspect the checkbox, and then tick/untick the box, you won’t see a “checked” attribute being applied.
If you are using jQuery I believe the correct way to detect if its checked is by using
.prop("checked")
instead of.attr("checked")
.Thanks
-
AuthorPosts