text()
methodYou can use the jQuery click()
method in combination with the text()
method to replace or toggle the text inside an element such as a link (i.e. an anchor <a>
), <div>
or <button>
element dynamically using the jQuery. Let's try out an example to see how this works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Toggle Text inside Elements</title>
<style>
button {
padding: 5px 10px;
font-size: 14px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$(this).text($(this).text() == 'Order by Alphabet' ? 'Order by Category' : 'Order by Alphabet');
});
});
</script>
</head>
<body>
<button type="button">Order by Alphabet</button>
<p><strong>Note:</strong> Click on the button to swap the text.</p>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Angular 12 Copy to Clipboard Example Tutorial
There are so many JavaScript plugin avai...Laravel 5.5 - simple crud operation with example
Today, we are sharing how to make s...How to make Custome Log System in Laravel?
In this article, I will share with you h...Laravel 8 CRUD operation example using Google Firebase
CRUD operation is a basic part of any we...jQuery get Value of Selected Radio Button
jQuery radio button is used when you wan...