Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:12:38+00:00 2026-06-02T04:12:38+00:00

I have this in my code: <div class=someClass> <div id=22 class=otherClass onclick=goToEdit();>Title</div> <div class=parent>Other

  • 0

I have this in my code:

<div class="someClass">
    <div id="22" class="otherClass" onclick="goToEdit();">Title</div>
    <div class="parent">Other title</div>
</div>

And:

function goToEdit()
{
    tree.selectItem($(event.target).attr('id'));
    btnMyButton_onclick();
}

In Chrome everything works fine, but in Mozilla it doesn’t react to the click event. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:12:40+00:00Added an answer on June 2, 2026 at 4:12 am

    I get error that event is not defined

    Doh! We should all have realized.

    The thing is that event is not a global on most browsers, though it is on IE and Chrome throws a bone to sites designed for IE by making it global as well as doing what it should do (passing it into the event handler function).

    Your best bet by far is to not use onclick="code" at all (see below), but you can also do this:

    <div id="22" class="otherClass" onclick="goToEdit(event);">Title</div>
    

    …which should work cross-browser. It works because the event object is defined in the special context in which onclick handlers are called (on browsers that do this in a standard way), or it’s a global (on IE), and so either way it’s defined at that point (but not necessarily, as a global, later in your goToEdit function — which is why we pass it in as an argument).

    But again, I wouldn’t do that. Instead, I’d make the id value valid for CSS by having it start with a letter, and use jQuery to hook up the handler:

    HTML:

    <div id="d22" class="otherClass">Title</div>
    

    JavaScript:

    $("#d22").click(goToEdit);
    function goToEdit(event) {
        tree.selectItem(event.target.id.substring(1));
        btnMyButton_onclick();
    }
    

    Notes:

    • I striped the d off the beginning of the id value before passing it on. I assume it was 22 for a reason.
    • There’s no reason to do $(event.target).attr('id'), just use event.target.id directly.
    • If the div may contain other elements (spans, ems, ps, etc.), note that event.target may not be the div, it may be a descendant element of the div. this will always be the div, though (jQuery sees to that), so:

      $("#d22").click(goToEdit);
      function goToEdit(event) {
          tree.selectItem(this.id.substring(1));
          btnMyButton_onclick();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this code: jQuery('div[class=someClass] :input:not(:button)').each(function() { if (input type is drop-down) {
I have this code: $('p', 'div.playlist').click(function(e){ if (e.target != this) { val = $(this).parent().attr('songid');
I have this code: <div class=changingClass></div> <div class=someClass></div> <div class=changingClass></div> For divs that have
i have a html code like this: <div class=someclass> <div class=childclass></div> <div class=checkclass></div> </div>
I have this HTML code: <div class='com_box'> <div class='com_box_c'> <div class='com_box_info'> <a id='quote'>quote</a> </div>
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
I have this code: $(div[id^='intCell']).mouseover(function() { $(this).css({ border:,1px solid #ff097c}); }).mouseout(function() { $(this).css({border:,1px solid
I have this code: <div classclassNameFather> <div class=className> <div class=className> <div.... (unlimited elements) </div>
Lets say we have this code: <div id='m1'> <div class=c></div> <div class=c></div> <div class=c></div>
I have an HTML Data which looks like: <div id=foo><a class=someClass href=http://somelink>Some Title</a></div> <div

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.