jquery selector not working, why?

前端 未结 8 611
挽巷
挽巷 2021-01-18 09:29

I simply want to manipulate the elements within the #content div, but $(\'#content\') doesn\'t seem to work, and yet in other places it does! My relevant code i

8条回答
  •  野的像风
    2021-01-18 10:04

    what led me to this page is

    I have this div with id LING_a_00224.s03

    and when I use jquery selector to get it

    $("#LING_a_00224.s03")
    

    I got not element (jquery selector not working)

    thats because the dot (.) in the id

    jquery will interpret it as All elements with id="LING_a_00224" and class="s03", not All elements with id="LING_a_00224.s03"

    so make sure that id selector does not contains jquery selector symbols like (.)

    or if you don't have control over elements ids, you can do

    selector=document.getElementById("LING_a_00224.s03");//JQuery selector sometimes fails because id may contains dot on it like #fn12.e2e
    $(selector).jqueryFunction()// wrap the JavaScript object into $() to convert it to jquery object
    

    hope this helps you

提交回复
热议问题