jQuery get DOM element as string

前端 未结 5 2132
走了就别回头了
走了就别回头了 2020-12-30 03:16

Say I have

$(\":input[type=text]:first\")

How do I get



        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 03:57

    An old trick:

    var selector = ":input[type=text]:first";
    
    var str = $(selector).clone().wrap('
    ').parent().html();

    Update You don't need to worry about calling .parent() since you're working with an orphaned clone of the original selector.

提交回复
热议问题