How jQuery selects ID elements starting with specific characters: Use jquery’s [[attribute=value]] selector to achieve this. The [[attribute=value]] selector selects each element with the specified attribute and Element starting with the specified string.
This method applies to all brands of computers
jQuery selects a specific Methods for ID elements starting with characters:
If you want to use jQuery to select elements whose ID starts with a specific character, you can use jquery's [attribute=value] selector. [attribute=value]
The selector selects every element with the specified attribute and starting with the specified string.
Syntax:
$("[attribute^='value']")
Let’s take a look at the use of [attribute^=value]
selector through examples.
Example: Select the element whose id starts with "demo" and change its background color
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> #demo_div { background: green; height: 100px; width: 200px; margin: 0 auto; color: white; line-height: 100px; } </style> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <body style = "text-align:center;"> <div id = "demo_div"> 这是div盒。</div> <p id = "demo_p" style ="font-size: 19px; font-weight: bold;"></p> <button onClick = "GFG_Fun()">点击这里</button> <p id = "demo_DOWN" style = "color: white; font-size: 24px; font-weight: bold;"> </p> <script> $('#demo_p').text("点击按钮,选择id以“demo”开头的元素并更改背景色。"); function GFG_Fun() { $( "[id^='demo']" ).css("background-color", "pink"); $('#demo_DOWN').text("测试文字!"); } </script> </body> </html>
Output:
Related Free learning recommendations: javascript (video)
The above is the detailed content of jQuery how to select ID elements starting with specific characters. For more information, please follow other related articles on the PHP Chinese website!