Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. why onblur Event Dosent Work For Div Element ???????????

why onblur Event Dosent Work For Div Element ???????????

Scheduled Pinned Locked Moved ASP.NET
helpjavascriptsecurityquestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mhd sbt
    wrote on last edited by
    #1

    Hello I have a Project that Use Very Div Element And Onblur Event In its. Because Of Security Reason We Switch From a version of JQuery To another . But We Face With This Problem : onblur Event dont Fire In Div Element But it Fire in input elements Like Textbox!!!!! and also onfocusout Event Fire in dive but i dont want use this.

    any help To solve this Problem can be useful thanks in advance

    Richard DeemingR 1 Reply Last reply
    0
    • M mhd sbt

      Hello I have a Project that Use Very Div Element And Onblur Event In its. Because Of Security Reason We Switch From a version of JQuery To another . But We Face With This Problem : onblur Event dont Fire In Div Element But it Fire in input elements Like Textbox!!!!! and also onfocusout Event Fire in dive but i dont want use this.

      any help To solve this Problem can be useful thanks in advance

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Literally the first result on Google for "html div onblur":

      http://stackoverflow.com/questions/18504139/div-onblur-function[^]

      For blur event to fire on an element, the element needs to receive focus first. But <div> elements do not receive focus by default. You can add tabindex="0" or contentEditable to your div so it will receive focus.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Literally the first result on Google for "html div onblur":

        http://stackoverflow.com/questions/18504139/div-onblur-function[^]

        For blur event to fire on an element, the element needs to receive focus first. But <div> elements do not receive focus by default. You can add tabindex="0" or contentEditable to your div so it will receive focus.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        mhd sbt
        wrote on last edited by
        #3

        ok but focusout event fire without set tabIndex=0 to div element , and this means that div has focus in this scenario!!!! i set "tabIndex=0" to div element for fire onblur and doesn't work!

        P 1 Reply Last reply
        0
        • M mhd sbt

          ok but focusout event fire without set tabIndex=0 to div element , and this means that div has focus in this scenario!!!! i set "tabIndex=0" to div element for fire onblur and doesn't work!

          P Offline
          P Offline
          Praneet Nadkar
          wrote on last edited by
          #4

          The blur event fires when focus is lost. By default, a div element cannot have the focus in the first place so it can not be lost. If you give the div a tabindex attribute, it will be able to accept focus:

          Test content here

          then attach focus and blur event handlers:

          document.getElementById("divid").onfocus = function() {
          alert('focus is hit');
          }
          document.getElementById("divid").onblur = function() {
          alert('blur is hit');
          }

          Hope this helps !! Regards, Praneet.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups