dynamic - Can I access a control by the last portion of its ID in jQuery? -
i have dynamically-created control gave id "ckbxemp"
as discovered "viewing source," sharepoint (or chrome, or "somebody") impertinently , presumptuously re-ids (and names it, , "for"s it) control, giving welsh-esque "ctl00_ctl24_g_1caf4ad1_092d_4224_bd10_28ab028aab50_ctl00_ckbxemp"
and (i assume reason), attempts manipulate "ckbxemp" via jquery fail - say, when short id gave it, so:
$(document).on("change", '#ckbxemp', function () { console.log('function has been reached'); if ($(this).is(":checked")) { alert("checked"); } else { alert("not checked"); } });
so can either change code this:
$(document).on("change", '#ctl00_ctl24_g_1caf4ad1_092d_4224_bd10_28ab028aab50_ctl00_ckbxemp', function () { console.log('function has been reached'); if ($(this).is(":checked")) { alert("checked"); } else { alert("not checked"); } });
...which okay one-time thing, have many dynamically-created controls want manipulate, , assume welshified, , bit of pain.
-or, there way id matches not exact "ends with". possible? if so, syntax that?
note: followup this question.
update
bizarrely enough (this starting irritating), doesn't work, either:
$(document).on("change", '#ctl00_ctl24_g_1caf4ad1_092d_4224_bd10_28ab028aab50_ctl00_ckbxemp', function () { console.log('function has been reached'); if ($(this).is(":checked")) { alert("checked"); } else { alert("not checked"); } });
update 2
robert mckee's answer, plus 1 question follow-up, have led working solution, codely:
$(document).on("change", '[id$=ckbxemp]', function () { alert('function has been reached'); if ($(this).is(":checked")) { alert("checked"); } else { alert("not checked"); } });
"this this. ain't else. this." - deer hunter
$(document).on("change", '[id$=ckbxemp]', function () {
Comments
Post a Comment