Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
76
rated 0 times [  82] [ 6]  / answers: 1 / hits: 36154  / 13 Years ago, mon, november 14, 2011, 12:00:00

Say I have



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


How do I get



<input type=text value= size=28 maxlength=140 tabindex=1 placeholder=search class=textbox name=q autocomplete=off>


Assuming I run this on SO?



Update I don't want to call .parent() since I have lots of other stuff in the parent element.


More From » jquery

 Answers
10

An old trick:



var selector = :input[type=text]:first;

var str = $(selector).clone().wrap('<div/>').parent().html();


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


[#89128] Saturday, November 12, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sidneyh

Total Points: 118
Total Questions: 108
Total Answers: 105

Location: Mali
Member since Fri, Jun 18, 2021
3 Years ago
sidneyh questions
Tue, Jun 7, 22, 00:00, 2 Years ago
Wed, Apr 13, 22, 00:00, 2 Years ago
Wed, Aug 12, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Fri, Apr 24, 20, 00:00, 4 Years ago
;