How to get the first child id inside the div using JQuery

前端 未结 7 1900
心在旅途
心在旅途 2020-12-18 21:47

How to get the first child id inside the div using JQuery.

Sample code:


      
7条回答
  •  失恋的感觉
    2020-12-18 22:29

    If you want immediate first child you need

    $(element).first();
    

    If you want particular first element in the dom from your element then use below

    var spanElement = $(elementId).find(".redClass :first");
    $(spanElement).addClass("yourClassHere");
    

    try out : http://jsfiddle.net/vgGbc/2/

提交回复
热议问题