Jquery Common function to hide elements by attribute -
i have many checkboxes , related textboxes in page. textboxes hidden default , show if related checkbox checked. how should write common function this, instead of function every checkbox.
something..like..:
$("input[type=checkbox]").click( function() { var x = $(this).attr("name"); $("[id=x]").toggle(this.checked); }); the 'name' of checkbox id of textbox.
you dont need attribute selector in context, since targeting id, use id selector below,
try,
$("#" + $(this).attr("name")).toggle(this.checked); full code,
$("input[type=checkbox]").change( function() { $("#" + $(this).attr("name")).toggle(this.checked); });
Comments
Post a Comment