Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 find anchor tag in div and add class using jQuery?
To find anchor tag in div, use a selector and the addClass() method adds a class using jQuery.
You can try to run the following code to learn how to find anchor tag in div and add class:
<html>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button1").click(function(){
$('#div1 a').addClass('myclass');
});
});
</script>
<style>
.myclass {
font-size: 25px;
}
</style>
</head>
<body>
<div id="div1">
<a href="http://www.google.com">Demo</a>
</div>
<div id="div2">
<p>This is demo text.</p>
</div>
<button id="button1">Click</button>
</body>
</html>Advertisements