Avatar of vb9666
vb9666Flag for United States of America asked on

onclick in DIV tag not working in Mozilla and older verisons of IE

I have some code where there is a onclick event in a DIV tag. It works in new version of IE but not in IE 7 & 8 and Mozilla. Anyone know why this isn't working?

Code:
            <div class="program" style="cursor:pointer;" onclick="window.location('GBR.aspx');">
                <div class="programImage"><img src="images/Programs1.gif" style="border:0" alt="AltImage" /></div>
                <div class="programInfo">
                    <div class="programTitle">Heading Text Here</div>
                    <div class="programLine"></div>
                    <div class="programDesc">Text here</div>
                </div>
            </div>
ASP.NETWeb Browsers

Avatar of undefined
Last Comment
APoPhySpt

8/22/2022 - Mon
APoPhySpt

hi,

A better option, especially since you are using jQuery, is to not use inline event handlers.

Instead, use this HTML:

<div class="program" style="cursor:pointer;" >

<script>
$(document).ready(function () {
    $(".program").on("click", function () {
        window.location('GBR.aspx');
    });
});

</script>

Open in new window

APoPhySpt

in the example I posted before the javascript must come after the div, but if you want to centralize the javascript on the top of the page os something like that you can put the '<script>' tags at the top with the following modification:

<script>

$(function() {

    $(document).ready(function () {
        $(".program").on("click", function () {
            window.location('GBR.aspx');
        });
    });

});

</script>

Open in new window


this tells the page to execute this function only after all the html has been loaded.
ASKER
vb9666

I don't see how the script is calling the function on the onclick event?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
vb9666

I tried this with javascript and calling a function and it does not work in Mozilla.

<div class="program" style="cursor:pointer;" onclick="javascript:OpenGBR();">
                <div class="programImage"><img src="images/Programs1.gif" style="border:0" alt="AltImage" /></div>
                <div class="programInfo">
                    <div class="programTitle">Heading Text Here</div>
                    <div class="programLine"></div>
                    <div class="programDesc">Text here</div>
                </div>
            </div>

    <script type="text/javascript" language="javascript">
        function OpenGBR()
        {
            window.location('GBR.aspx');
        }
    </script>
ASKER
vb9666

I think the issue has something to do with the window.location. It works fine in IE but not Mozilla. If I change the code to window.open then it works in both browsers but I don't want to open a new window.
ASKER CERTIFIED SOLUTION
APoPhySpt

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question