From a78b7b4ac2ff54998137abc7eb13c8008cd9cd55 Mon Sep 17 00:00:00 2001 From: Derek Johnson Date: Tue, 4 Dec 2018 17:37:03 -0600 Subject: [PATCH] Add attribute selector to the list of selectors (#23491) Explains how to use the attribute selector --- guide/english/jquery/jquery-selectors/index.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/guide/english/jquery/jquery-selectors/index.md b/guide/english/jquery/jquery-selectors/index.md index 7740c02d4e..3fce3a112b 100644 --- a/guide/english/jquery/jquery-selectors/index.md +++ b/guide/english/jquery/jquery-selectors/index.md @@ -73,6 +73,24 @@ As with the class selector, this can also be used in combination with a tag name $("h1#headline").css("font-size", "2em"); ``` +### Selecting by attribute value +If you want to select elements with a certain attribute, use ([attributeName="value"]). +```html + +``` +```javascript +$("[name='myInput']").value("Test"); // sets input value to "Test" +``` + +You can also use the attribute selector in combination with a tag name to be more specific. +```html +`
+ +``` +```javascript +$("input[name='myElement']").remove(); // removes the input field not the button +``` + ### Selectors that act as filters There are also selectors that act as filters - they will usually start with colons. For example, the `:first` selector selects the element that is the first child of its parent. Here's an example of an unordered list with some list items. The jQuery selector below the list selects the first `
  • ` element in the list--the "One" list item--and then uses the `.css` method to turn the text green.