Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get DOM element as string

Tags:

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.

like image 460
bevacqua Avatar asked Nov 14 '11 19:11

bevacqua


People also ask

How to select DOM elements in jQuery?

If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object. var myDomElement = document. getElementById( "foo" ); // A plain DOM element. $( myDomElement ).

How do I get text inside a div using jQuery?

To get the value of div content in jQuery, use the text() method. The text( ) method gets the combined text contents of all matched elements. This method works for both on XML and XHTML documents.

What does parseHTML do?

parseHTML uses native methods to convert the string to a set of DOM nodes, which can then be inserted into the document. These methods do render all trailing or leading text (even if that's just whitespace).

How do I get just the text from HTML in jQuery?

You could use $('. gettext'). text(); in jQuery.


1 Answers

How about

$(selector).prop("outerHTML");
like image 98
William Avatar answered Sep 18 '22 09:09

William