Click event not working for dynamically added Li->span->id

前端 未结 1 518
一整个雨季
一整个雨季 2021-01-29 01:45

Click event not working for dynamically added Li->span->id

    case\"101\" :   strLink = \"
  • 相关标签:
    1条回答
    • 2021-01-29 02:22

      You have a missing quote in there, which is causing the browser to misinterpret the ID:

      case"101" :   strLink = "<li style='cursor:pointer'><a data-scroll><span id='div101'>Form 101</span></a></li>"; $('.sidebar-nav').append(strLink); break;
      

      You also have to make sure to add the handler after the element has been injected into the body. If the element isn't around, it will not register the click event.

      0 讨论(0)
    提交回复
    热议问题