Faraz Durrani Faraz Durrani - 1 year ago 62
HTML Question

How do I select a id inside bootstrap's label tag

I have html like this:

`<label class="radio-inline"><input type="radio" disabled="true" id="ojtm.inform_infoy" name="ojtm.inform_info" path="ojtm.inform_info" value="Y">Yes</label>`
$(document).ready(function() {
$("#ojtm.inform_infoy").click(function(event) {
console.log("ojtm.inform_infoYY is clicked: ");
//trying to do something

I am trying to get its id using jquery to do something. But for some reason nothing is printing in console. How do I select that id inside label tag? Thanks

Answer Source

Dot is a metacharacter in jquery, Escape it.

$("#ojtm\\.inform_infoy").click(function(event) {

And the best practice is to avoid using . in id/class attributes as it will cause problems like this. Additionally, you should prefer using change event over radio button instead of using click event.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download