- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write a jQuery selector to find links with # in href attribute?
Example
You can try to run the following code to write a jQuery selector to find links with # in href. Here,^ is used to find links starting with # in href.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('a[href^="#"]').click(function(){ alert('Success! Selected link starting with # in href.'); }); }); </script> </head> <body> <a href="#demo" title="new" >Demo</a><br> <a href="/cplusplus/" title="C++ Tutorial" >C++</a> </body> </html>
- Related Articles
- How to combine a class selector and an attribute selector with jQuery?
- How to use *= operator in jQuery attribute selector?
- How to make jQuery attribute selector case insensitive?
- How to change the href attribute for a hyperlink using jQuery?
- How do we use jQuery Attribute selector with a period?
- How to pass a variable into a jQuery attribute-contains selector?
- jQuery [attribute!=value] Selector
- How do we use # in jQuery Attribute Selector?
- How to style a href links in React using Tailwind CSS?
- How to find the href attribute of a link in a document in JavaScript?
- How to write a jQuery selector for the label of a checkbox?
- How to use href attribute in HTML Page?
- How to set cursor style to pointer for links without href?
- How can BeautifulSoup be used to extract ‘href’ links from a website?
- How to use universal (*) selector in jQuery?

Advertisements