jquery selector not working, why?

前端 未结 8 718
挽巷
挽巷 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 09:42

    id is a plain DOM property/attribute, and works with plain DOM objects, not jQuery objects.

    You would do this in jQuery:

    $("#content").attr('id');
    

    which equals:

    document.getElementById('content').id
    

    or

    $("#content")[0].id; //[0] gets the first DOM object in the collection
    

提交回复
热议问题