Home > Web Front-end > JS Tutorial > jQuery gets DIV attributes and binds CheckBox

jQuery gets DIV attributes and binds CheckBox

php中世界最好的语言
Release: 2018-03-15 15:16:21
Original
1716 people have browsed it

This time I will bring you jQueryGet DIVpropertiesand bind CheckBox, jQuery gets DIV properties and binds CheckBoxWhat are the precautions? The following is a practical case, let’s take a look.

Without further ado, let’s go straight to the code

<!DOCTYPE html>
<html>
<head lang="en">
  <meta charset="UTF-8">
  <title>JqueryTest</title>
  <script src="js/jquery-1.8.3.min.js"></script>
  <script>
	$(document).ready(function () {
		$('input').click(function(e){
			e.stopPropagation();
			var parent = $(this).parent();
			$(this).is(':checked') ? parent.css('background-color','#CCC') : parent.css('background-color','#FFF');
		});
		$('p').click(function(){
			$(this).find(':checkbox').click();
			if($(this).css('background-color') == 'rgb(255, 255, 255)'){
				$(this).css('background-color', '#CCC');
			}else{
				$(this).css('background-color', '#FFF');
			}
		});
	});
	</script>
</head>
<body>
  <p>
    <input type="checkbox" />A
  </p>
  <p>
    <input type="checkbox" />B
  </p>
  <p>
    <input type="checkbox" />C
  </p>
</body>
</html>
Copy after login

Screenshot of the effect:

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Using tabs in jQuery EasyUI tab panel

Practical jQuery drawer-style online customer service

The above is the detailed content of jQuery gets DIV attributes and binds CheckBox. 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