Home > Web Front-end > Front-end Q&A > How to make the cursor disappear with jquery

How to make the cursor disappear with jquery

青灯夜游
Release: 2022-06-08 17:14:01
Original
2447 people have browsed it

Two methods: 1. Use css() to set the cursor color style, the syntax is "element.css("caret-color","transparent")"; 2. Use attr(), the syntax is "element. attr("style","caret-color:transparent")".

How to make the cursor disappear with jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

In HTML, you can make the cursor disappear by setting the cursor color to transparent, that is, adding the caret-color:transparent; style;

The following introduces jquery settings for transparency Two methods of cursor.

Method 1: Use css() to directly set the caret-color attribute

The css() method sets or returns one or more style attributes of the selected element.

Just set the value of the caret-color attribute to transparent.

元素对象.css("caret-color","transparent");
Copy after login

Example:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<script src="js/jquery-3.2.1.min.js"></script>
		<script>
			$(document).ready(function() {
				$("button").click(function() {
					$("input").css("caret-color","transparent");
				});
			});
		</script>
	</head>
	<body>

		<input type="text" /><br><br>
		<button>让光标消失</button>

	</body>
</html>
Copy after login

How to make the cursor disappear with jquery

2. Use attr() to set the style attribute and add caret-color:transparent; style

attr() can set element attributes.

Just set the style attribute and add caret-color:transparent; inline style.

Example:

$(document).ready(function() {
	$("button").click(function() {
		$("input").attr("style","caret-color:transparent");
	});
});
Copy after login

How to make the cursor disappear with jquery

[Recommended learning: jQuery video tutorial, web front-end video]

The above is the detailed content of How to make the cursor disappear with jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template