Jonathan Baran
Jonathan Baran

Reputation: 291

jQuery ID selector not working for IE7 (.show()/.hide())

On jQuery load I'm trying to hide/show certain divs depending on condition. Everything works outside of IE7. I have broken it down and I have found that the following class selector will work:

$('.medication_div').hide();

But, the ID selector, which I need, does not (Note: I tried harding code values which did also not work.

//Get the name of the medication selected
var medication_selected = $("ul#medication_classes li:last-child p").text();
//Show the div associated with the selected medication card
$("#"+medication_selected).show();

Here is the HTML code generated after run:

<ul id="medication_classes">
            <li>
                <p>Celexa</p>
                <input id="Meds_0" name="Meds[0]" type="hidden" value="Celexa" />
            </li>

            <li>
                <p>Lisinopril</p>
                <input id="Meds_1" name="Meds[1]" type="hidden" value="Lisinopril" />
            </li>
        </ul>
        <div id="results_detail" class="grid_12 alpha">
            <ul>
                <li>

                    <div class="medication_div" id="Celexa">
                        <p id="class_trigger">Protocol Set Triggering: General<input id="Celexa_ProtocolSetID" name="Celexa[ProtocolSetID]" type="hidden" value="1" /></p><br>
                        <p class="left_input">Does the patient still have active refills for Celexa?</p> 
                        <div class="right_input">No:<input id="Celexa_ActiveRefills_No" name="Celexa[ActiveRefills]" type="radio" value="No" />  Yes:<input id="Celexa_ActiveRefills_Yes" name="Celexa[ActiveRefills]" type="radio" value="Yes" /></div><br/>
                        <div class="clear"></div>
                        <div id="Celexa_notActive">
                            <p>Approve the Celexa refill as indicated in the patient record.</p>

                        </div>


                        <div id="Celexa_active">
                        <p class="left_input" id="dose_change">When was the dosage for this medication last changed?</p> <div class="right_input"><input class="date" id="Celexa_MedicationChangeDate" name="Celexa[MedicationChangeDate]" type="text" /></div><br/>
                        <div class="clear"></div>


                        <div class="table_header med_info">
                            <h5>Fill in the following as much possible in order to find the most relevant protocol.</h5>
                        </div>

                        <table width="846">
                            <tr id="labels">
                                <th width="33%">Name</th>
                                <th width="33%">Value</th>
                                <th width="33%">Result Date</th>
                            </tr>   
                            <tr>
                                <td width="33%">Medication Start<input id="Celexa_TestResult_0_Name" name="Celexa[TestResult][0][Name]" type="hidden" value="Medication Start" />

                                </td>
                                <td width="33%">
                                    <p>N/A</p>
                                </td>
                                <td width="33%">
                                    <input class="date" id="Celexa_TestResult_0_Date" name="Celexa[TestResult][0][Date]" type="text" />
                                </td>
                            </tr>

                        </table>

                        <label>Note to physician about refill request:</label><textarea class="md_note" id="Celexa_Note" name="Celexa[Note]"></textarea>
                    </div>
                    </div>
                </li>
                <li>
                    <div class="medication_div" id="Lisinopril">
                        <p id="class_trigger">Protocol Set Triggering: Hypertension Medications<input id="Lisinopril_ProtocolSetID" name="Lisinopril[ProtocolSetID]" type="hidden" value="4" /></p><br>

                        <p class="left_input">Does the patient still have active refills for Lisinopril?</p> 
                        <div class="right_input">No:<input id="Lisinopril_ActiveRefills_No" name="Lisinopril[ActiveRefills]" type="radio" value="No" />  Yes:<input id="Lisinopril_ActiveRefills_Yes" name="Lisinopril[ActiveRefills]" type="radio" value="Yes" /></div><br/>
                        <div class="clear"></div>
                        <div id="Lisinopril_notActive">
                            <p>Approve the Lisinopril refill as indicated in the patient record.</p>
                        </div>


                        <div id="Lisinopril_active">

                        <p class="left_input" id="dose_change">When was the dosage for this medication last changed?</p> <div class="right_input"><input class="date" id="Lisinopril_MedicationChangeDate" name="Lisinopril[MedicationChangeDate]" type="text" /></div><br/>
                        <div class="clear"></div>


                        <div class="table_header med_info">
                            <h5>Fill in the following as much possible in order to find the most relevant protocol.</h5>
                        </div>
                        <table width="846">
                            <tr id="labels">

                                <th width="33%">Name</th>
                                <th width="33%">Value</th>
                                <th width="33%">Result Date</th>
                            </tr>   
                            <tr>
                                <td width="33%">Medication Start<input id="Lisinopril_TestResult_0_Name" name="Lisinopril[TestResult][0][Name]" type="hidden" value="Medication Start" />
                                </td>

                                <td width="33%">
                                    <p>N/A</p>
                                </td>
                                <td width="33%">
                                    <input class="date" id="Lisinopril_TestResult_0_Date" name="Lisinopril[TestResult][0][Date]" type="text" />
                                </td>
                            </tr>
                            <tr>

                                <td width="33%">Creatinine<input id="Lisinopril_TestResult_1_Name" name="Lisinopril[TestResult][1][Name]" type="hidden" value="Creatinine" />
                                </td>
                                <td width="33%">
                                    <input id="Lisinopril_TestResult_1_Value" name="Lisinopril[TestResult][1][Value]" type="text" />
                                </td>
                                <td width="33%">
                                    <input class="date" id="Lisinopril_TestResult_1_Date" name="Lisinopril[TestResult][1][Date]" type="text" />
                                </td>

                            </tr>
                        </table>

                        <label>Note to physician about refill request:</label><textarea class="md_note" id="Lisinopril_Note" name="Lisinopril[Note]"></textarea>
                    </div>
                    </div>
                </li>
            </ul>
        </div>

When hard-coding for the above example I have hard-coded to no avail:

$("#Celexa").show();

Any ideas?

Upvotes: 1

Views: 1852

Answers (2)

Jonathan Baran
Jonathan Baran

Reputation: 291

Turns out the Rails code was generating an extra character which was only getting interpreted in IE7. To this point, I'm still not sure what the character is (possibly non-unicode), but I fixed the problem by using the jQuery wildcard selector:

$("div[id^="+medication_selected+"]").show();

Upvotes: 1

Guy
Guy

Reputation: 13286

worked fine on my ie7. inspect your css / style in firefox.

btw - try using json, templates and the jquery data for better results. for example:

HTML:

<p>select one:</p>
<ul id="medication_classes">
</ul>
 <div id="medication_detail">
<p>Protocol Set Triggering: <span class="data-protocol">General</span></p>
<p>Does the patient still have active refills for <span class="data-name">Celexa</span>?</p> 
<p>No:<input type="radio" value="No" />  Yes:<input type="radio" value="Yes" /></p>
<p>Approve the <span class="data-name">Celexa</span> refill as indicated in the patient record.</p>
<p>When was the dosage for this medication last changed?</p> 
<p><input class="date" /></p>
<p>Fill in the following as much possible in order to find the most relevant protocol.</p>

JS:

$(function () {
        var medications = [
            { name: 'Celexa', protocol: 'General' },
            { name: 'Lisinopril ', protocol: 'Hypertension Medications' }
        ];


        for (var medicationID in medications) {
            var medication = medications[medicationID];

            $('<li>')
                .data('medicineData', medication)
                .text(medication.name)
                .appendTo('#medication_classes')
                .click(function () {
                    var medicineData = $(this).data('medicineData');
                    $('.data-name').text(medicineData.name);
                    $('.data-protocol').text(medicineData.protocol);
                });
        }

    });

maybe use pure - which is a good templating engine.

Upvotes: 0

Related Questions