---
title: "goquery: HTML classes and parser options in Go | VulCode"
description: "Two changes to goquery, a Go library for HTML: RemoveClass with repeated classes, and parser options that let selectors reach inside <noscript> elements."
url: "https://vulcode.com/en/opensource/contributions/goquery"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

PuerkitoBio/goquery

# goquery

A Go library for traversing and changing HTML documents in the style of jQuery, built on the golang.org/x/net/html parser.

[See the repository](https://github.com/PuerkitoBio/goquery) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Go
- **GitHub stars**: 14,995
- **Merged changes**: 2

## What we changed

RemoveClass and ToggleClass remove a class even when the source repeats it side by side. A new NewDocumentFromReaderWithOptions constructor passes HTML parser options through, such as turning scripting off so selectors can reach inside <noscript>.

### What this work shows

- The golang.org/x/net/html parser

- The HTML spec: <noscript> and scripting

- Backward-compatible API design in Go

- Table-driven tests in Go

What was broken

### RemoveClass left a repeated class behind

For class="a a", after RemoveClass("a") the element still had class a. A single strings.ReplaceAll pass missed the second occurrence, because adjacent classes share the space between them. ToggleClass had the same bug, so the next toggle switched the class off instead of on.

How we fixed it

### Removing until none are left

A removeClassFromClasses helper removes one occurrence at a time and rescans from the start until none are left. RemoveClass and ToggleClass both use it, and tests cover adjacent, tripled, leading, trailing and interleaved repeats.

[#603](https://github.com/PuerkitoBio/goquery/pull/603)

What was broken

### Selectors could not reach inside <noscript>

The HTML parser assumes scripting is on, and the spec then parses <noscript> content as raw text where no selector can find anything. The html package has a ParseOptionEnableScripting option, but goquery called html.Parse and there was no way to pass it.

How we fixed it

### A constructor with parser options

We added NewDocumentFromReaderWithOptions, which accepts parser options. The document keeps them and applies them to HTML added later too, for example through AppendHtml, AfterHtml or WrapHtml, while the existing API stays unchanged.

[#602](https://github.com/PuerkitoBio/goquery/pull/602)

## Merged changes 2

- [#602 Expose html parse options (addresses #139, noscript) Merged 30 September 2026](https://github.com/PuerkitoBio/goquery/pull/602)

- [#603 RemoveClass leaves a class behind when the source repeats it Merged 7 September 2026](https://github.com/PuerkitoBio/goquery/pull/603)

## What it taught us

A library for HTML from the web must cope with messy source where the same class repeats several times. We add new API narrowly and without breaking compatibility, and state its reach plainly.

[More about this technology: Golang](https://vulcode.com/en/technologies/go)

## Other projects we write code for

- [**urfave/cli** Go · 24,329 stars A declarative Go package for building command line tools.](https://vulcode.com/en/opensource/contributions/urfave-cli)

- [**chezmoi** Go · 22,342 stars A dotfiles manager that keeps the same settings on many different machines, securely.](https://vulcode.com/en/opensource/contributions/chezmoi)

- [**Ebitengine** Go · 13,647 stars A 2D game engine in Go, used in games released for computers, phones, browsers and consoles.](https://vulcode.com/en/opensource/contributions/ebiten)

- [**Fission** Go · 8,950 stars A serverless functions framework for Kubernetes that runs code as functions and scales them down to zero when they are idle.](https://vulcode.com/en/opensource/contributions/fission)

- [**Concourse** Go · 7,944 stars A container-based automation system written in Go and used mostly for CI/CD. Pipelines and tasks are described in YAML files.](https://vulcode.com/en/opensource/contributions/concourse)

- [**dromara/carbon** Go · 5,225 stars A Go package for dates and times with a simple, readable API, with helpers such as the start and end of a minute, a day or a century.](https://vulcode.com/en/opensource/contributions/dromara-carbon)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
