මචංල මම JQuery ගැන වැඩිය දන්නෑ. මට මචංල මේක කරන විදිය පොඩ්ඩක් පැහැදිලි කරල දෙන්න. මම කරන්න උත්සාහ කරන දේ සරල වෙන්න බොහොම සරල කෝඩ් එකක් ලිව්ව. මේ තියෙන්නේ ඒක. ටෙස්ට් කරන්න ඔය කෝඩ් එක කොපි කරල blank .html පේජ් එකකට සේව් කරල browser එකෙන් Open කරන්න.
මට මචංල වෙන්න ඕන ඔය එක් එක් බටන් එක click කරාම ඒකට අදාල h2 එක විතරක් hide වෙන්න. ඔතනදි නම් එක button එකක් click කරාම ඔක්කොම H2 hide වෙනවනේ.
මට මචංල මේක එකින් එක id දාල නෙමේ කරගන්න ඕන. එකම කෝඩ් එකෙන් මේ වගේ elements group ඕන ප්රමානයක් handle කරන්න පුලුවන් වෙන්න ඕන. අන්න එතන තමයි වැදගත්. නැත්නම් element එකෙන් එකට js කෝඩ් එක update කරන්න වෙනව.
PHP:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<button>hide me 1</button>
<h2 hideme>hide me 1</h2>
<button>hide me 2</button>
<h2 hideme>hide me 2</h2>
<button>hide me 3</button>
<h2 hideme>hide me 3</h2>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function() {
var button = $('button');
button.click(function() {
$('h2[hideme]').hide();
});
});
</script>
</body>
</html>
</body>
</html>
මට මචංල වෙන්න ඕන ඔය එක් එක් බටන් එක click කරාම ඒකට අදාල h2 එක විතරක් hide වෙන්න. ඔතනදි නම් එක button එකක් click කරාම ඔක්කොම H2 hide වෙනවනේ.
මට මචංල මේක එකින් එක id දාල නෙමේ කරගන්න ඕන. එකම කෝඩ් එකෙන් මේ වගේ elements group ඕන ප්රමානයක් handle කරන්න පුලුවන් වෙන්න ඕන. අන්න එතන තමයි වැදගත්. නැත්නම් element එකෙන් එකට js කෝඩ් එක update කරන්න වෙනව.

Last edited:


