I want the above function to just "hit" the h3's with ID "someid_1" and "someid_2" when I click "someid_3" for instance. This have to be a dynamic function, as the ID's, amount etc. can vary.
I have a php-based form with radio-buttons with following labels - I've been trying to get the text-value of these labels, but I keep getting empty variables - it seems it doesn't pick up the value at all.
$("#paamelding_form select").change(function () { $("option:selected").click(function() { if ($(this).hasClass("double_0") || $(":selected").hasClass("")) { var oldID = ($(this).parent("select").attr("id").match(/\d+$/)); var newID = ++oldID; alert("remove" + newID); $("#pulje_" + newID).removeAttr("disabled","disabled").css({ 'border-color' : ' #000', 'background-color' : '#ddd'}); $.cookie("pulje_" + newID +"","enabled", { path: '/' }); alert($.cookie("pulje_" + newID + "")); $("label[for='pulje_" + newID + "']").css({ 'color' : '#2F5376'}).find(".double_warning").remove(); } if ($(this).hasClass("double_1")) { var oldID = ($(this).parent("select").attr("id").match(/\d+$/)); var newID = ++oldID; alert("add" + newID); $("#pulje_" + newID).attr("disabled","disabled").css({ 'border-color' : ' #777', 'background-color' : 'eee'}); $.cookie("pulje_" + newID +"","disabled", { path: '/' }); alert($.cookie("pulje_" + newID + "")); $("label[for='pulje_" + newID + "']").css({ 'color' : '#2F5376'}).find(".double_warning").remove(); if($("option:selected").text() == 'Gopher') { var double_warning = "<small class='double_warning'><span class='double_warning' style='color: red;'>Du valgte gopher i forrige delpulje og vil bli satt opp som gopher i denne delpuljen også</span></small>"; } else { var double_warning = "<small class='double_warning'><span class='double_warning' style='color: red;'>Du valgte et spill som varer i to delpuljer, dette valget er derfor ikke tilgjengelig</span></small>"; } $("label[for='pulje_" + newID + "']").css({ 'color' : '#aaa'}).append(double_warning); } });
});
This works, but only for mouseclicks. It's probably also extremely crappy code to begin with - I'm pretty new to jquery, and I tend to go with what works for now - and this does. But I'd like it to work for both mouseclicks and when people navigate the form using the keyboard - any hints or improvements that can be done to the code to make it behave like I want it to?