Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the capture method based on what you need to keep: use .html() for an element’s inner markup, .text() for its descendant text, .serialize() for form values, and the browser’s Selection API for text a user highlighted. None of those jQuery methods takes a screenshot. Capturing rendered pixels is a separate browser or screenshot-service task.

Choose the output you want

“Capture part of a webpage” can mean several different things. Before writing code, decide whether you need HTML markup, readable text, submitted form values, a user’s highlighted text, or an image of what the browser rendered. Those outputs are not interchangeable: markup does not preserve pixels, text does not preserve element structure, and a screenshot does not give you the original HTML source.

What you need Use What it returns
Contents inside one element $(selector).html() Inner HTML of the first matched element
Readable text inside an element $(selector).text() Combined descendant text
Form data as a query string $(form).serialize() URL-encoded successful form controls
Text the user highlighted window.getSelection() The current browser selection
Rendered appearance Browser display capture or a screenshot service Image pixels, subject to browser capabilities and permissions

Get the HTML inside an element with jQuery

Use .html() as a getter when you need the selected element’s inner markup:

const html = $("#article-section").html();
console.log(html);

If the element contains a heading and a paragraph, the result is the markup for those children. It does not include the outer <section id="article-section"> wrapper, the document head, or the rest of the page. The getter uses the browser’s innerHTML property, so it returns the live DOM’s serialized representation—not a guaranteed byte-for-byte copy of the original server response.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Be explicit when a selector can match more than one element

A selector may match several nodes, but the .html() getter returns the contents of the first match. Make the target deliberate, for example with a unique ID, a more specific selector, .first(), or .eq(index):

const firstCardHtml = $(".card").first().html();
const thirdCardHtml = $(".card").eq(2).html();

Indexes passed to .eq() start at zero, so .eq(2) selects the third match. If no element matches, the getter returns undefined; check that the selector found a target before using the result.

Capture the wrapper too, if you need it

.html() is for contents, not the selected element itself. If downstream code needs the element’s tag and attributes as well as its children, clone the element and read the clone’s outer HTML:

const $target = $("#article-section");
const outerHtml = $target.length ? $target[0].outerHTML : "";

This still serializes the current DOM; it is not a copy of the original network response. It is also different from a visual capture: styles, layout, and rendered pixels are not represented by the HTML string alone.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Get text from an element in jQuery

Use .text() when the output should be text rather than markup:

const text = $("#article-section").text();
console.log(text);

The method collects text from the matched element and its descendants. If the selector matches several elements, their descendant text is combined. It does not preserve the HTML hierarchy or guarantee the same spacing and line breaks a person sees on screen. Browser parsing and whitespace in the document can affect the result.

Normalize whitespace only when your output calls for it

If you want a compact single-line string, normalize runs of whitespace explicitly:

const rawText = $("#article-section").text();
const oneLine = rawText.replace(/s+/g, " ").trim();

Do not normalize automatically if line breaks or spacing carry meaning—for example, when extracting preformatted text. For an <input> or <textarea>, read its current value with .val(); its entered value is not the same as the element’s text content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Capture form values as a query string

For a form, .serialize() creates URL-encoded text from successful form controls:

const queryString = $("#contact-form").serialize();
console.log(queryString);

A result might look like name=Sam&topic=Support. It is suitable for form-style query data, not for preserving the form’s markup or taking a screenshot.

Know what serialization includes

  • Controls need a name attribute to contribute a value.
  • Unchecked checkboxes and radio buttons are excluded.
  • File input data is not included in the serialized string.
  • Select the form itself or its controls, not both together; selecting a form and its child controls together can duplicate values.

If a field seems to be missing, inspect its name, checked state, and control type before assuming the selector is wrong.

Capture text a user selected on the page

When the target is the text the user highlighted, use the browser’s native Selection API rather than a jQuery text getter:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
const selection = window.getSelection();
const selectedText = selection ? selection.toString() : "";
console.log(selectedText);

This reads the current selection, which may be empty if the user has not highlighted text. For more detailed handling, first check that the selection has at least one range, then inspect selection.getRangeAt(0). A Range represents a contiguous portion of the document and can cover whole nodes or part of a text node.

Keep selection handling separate from focus handling. Browser behavior can differ when code changes a selection programmatically; reading the current selection does not itself determine which control has focus.

Take a screenshot of a rendered part of a page

Neither .html() nor .text() captures an image. They read DOM content. A screenshot captures rendered pixels and follows a different path, usually through browser display-capture capabilities or a service that renders a URL.

In the browser: account for permission and capture semantics

A browser display-capture flow asks the user agent to let the user choose what to share. Depending on the browser and supported APIs, Element Capture can restrict a captured stream to a rendered DOM tree and its descendants. Region Capture instead crops to an element’s bounding box; overlapping content in that region may also appear. These approaches are not equivalent, and availability can vary by browser. Check compatibility for the browsers you support before relying on either one.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

A typical pixel-capture pipeline requests a display stream, targets the desired element or region using the available capture API, grabs a frame with ImageCapture.grabFrame(), then draws the bitmap to a canvas and encodes it as PNG. It requires browser support and user permission. It is not a silent jQuery operation, and the browser’s selection and sharing behavior are part of the experience.

For a screenshot of an already-open page in your own application, use the browser capabilities supported by your target environment and explain the sharing prompt to the user. For a screenshot of a public URL rendered on a server, a screenshot API is a different option; it does not capture a visitor’s private, unsaved state in their current tab.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API with CSS-selector element capture, so you can request an image of a page element without implementing a browser display-capture flow. For example, this cURL request captures the element selected by #article-section from a URL:

curl -G "https://api.screenshotneo.com/v1/shot" 
  -d access_key=YOUR_API_KEY 
  --data-urlencode url=https://stripe.com 
  -d selector='#article-section' 
  -o shot.webp

See the ScreenshotNeo API documentation for request parameters and response details. Its consent handling can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots. Sign up for free and try 1,000 screenshots a month with no card.

Keep captured HTML safe

Reading markup with .html() is not the same as inserting it into a page. The security risk arises when HTML is accepted and interpreted, particularly if it came from an untrusted source. jQuery warns: “Do not use these methods to insert strings obtained from untrusted sources such as URL query parameters, cookies, or form inputs.” Script tags or executable attributes in inserted HTML can run code.

If you only need to display a string as text, use .text() to create text content instead of interpreting the string as HTML. Do not treat a string read from a page as safe simply because it came from the DOM; its origin and what you do with it still matter.

Troubleshoot common capture problems

  • .html() returns undefined: the selector probably did not match. Check the selector spelling, whether the code runs after the element exists, and the length of the jQuery result.
  • You got the wrong element’s contents: your selector matched multiple elements. Narrow it, or choose explicitly with .first() or .eq(index).
  • The wrapper or attributes are missing: .html() returns inner markup only. Use the target node’s outerHTML if you need its wrapper, attributes, and children.
  • The output’s spacing differs from the page: DOM text does not preserve visual layout. Decide whether to keep the raw text or normalize whitespace for your particular output.
  • A field is absent from .serialize(): verify its name, whether a checkbox or radio button is checked, and whether it is a file input.
  • The screenshot flow does not start: display capture needs browser support and user permission. Check the browser’s current compatibility and ensure the user can complete its sharing choice.
  • The captured region includes overlapping content: Region Capture follows an element’s bounding box, so content overlapping that area may be visible. Confirm that region cropping matches your intended result.

Which method should you use?

  1. Need child markup for inspection or further processing? Use .html() and select one target deliberately.
  2. Need the words inside a section? Use .text(); normalize whitespace only if your consumer needs it.
  3. Need submitted values? Use .serialize() and account for successful-control rules.
  4. Need a visitor’s highlighted text? Read the native browser selection.
  5. Need pixels? Use a supported, permission-based browser capture flow for the current browser context, or a screenshot service for a URL rendered independently.

If you need the exact original response bytes rather than a live DOM representation, neither .html() nor .text() is the right representation. The DOM getter can reflect parsing and serialization changes, while screen capture represents rendered pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.