In this tutorial are presented some basic effects that you can create with jQuery.
$('selector').hide('duration');- "duration" - (optional) indicates the speed of the hiding animation. It can be the strings "fast" and "slow", or a number that indicates the speed in milliseconds.
<style type="text/css"><!-- .cls { cursor:pointer; text-decoration:underline; } --></style> <script type="text/javascript"><!-- $(document).ready(function() { // when click on a <span> with class="cls", hide its parent $('span.cls').click(function(){ $(this).parent().hide('slow'); }); }); --></script> <div>Free Web Development Courses, jQuery tutorial ... <span class="cls">Close</span>.</div> <div>Other Free Web programming Courses on coursesweb.net... <span class="cls">Close</span>.</div>The code above hides (with a slow animation) the elements which contain a <span> tag with class="cls", when the user click on that <span>.
$('selector').hide('duration', function() { // code to execute });
<style type="text/css"><!-- .cls { cursor:pointer; text-decoration:underline; } --></style> <script type="text/javascript"><!-- $(document).ready(function() { // when click on a <span> with class="cls", hide its parent $('span.cls').click(function(){ $(this).parent().hide('slow', function() { alert('Closed'); }); }); }); --></script> <div>Free Web Development Courses, jQuery tutorial ... <span class="cls">Close</span>.</div> <div>Other Free Web programming Courses on coursesweb.net... <span class="cls">Close</span>.</div>This time we added a function with an alert() to be executed once the hiding animation is complete.
$('selector').show('duration');- "duration" - it is optional, indicates the speed of the showing animation. It can be the strings "fast" and "slow", or a number that indicates the speed in milliseconds.
$('selector').show('duration', function() { // code to execute });
<script type="text/javascript"><!-- $(document).ready(function() { // reveal the tag with id="idd", when the tag with id="btn" is clicked $('#btn').click(function(){ $('#idd').show('slow', function() { $('#btn').hide(650); }); }); }); --></script> <div id="idd" style="display:none;">Free Web Development Courses, jQuery tutorial.</div> <button id="btn">Show</button>This code displays the following result, when the user clicks the "Show" button, the <div> with id="idd" is revealed slowly, then once the animation is complete the button will be hid (in 650 milliseconds).
if ($('#theID').is(':visible')) { // code to execute when is visible }To test if an element is hidden, you can use this code:
if ($('#theID').is(':hidden')) { // code to execute when is hidden }
<script type="text/javascript"><!-- $(document).ready(function() { // when click on the tag with id="btn" $('#btn').click(function() { // if the tag with id="idd" is hidden, reveals it and turn its text blue if ($('#idd').is(':hidden')) { $('#idd').show('slow').css('color', 'blue'); } else if ($('#idd').is(':visible')) { // else, if the tag with id="idd" is visible, sets a background color $('#idd').css('background', '#cdfecd'); } }); }); --></script> <div id="idd" style="display:none;">Div tag initially hidden.</div> <button id="btn">Click</button>The <div> is initially hidden, when the user clicks on the button "Click" first time, the <div> is revealed (with blue text), when the user clicks on the button second time, sets a background to that DIV.
$(document).ready(function() { // when click on the tag with id="btn" $('#btn').click(function() { $('#idd:visible').css('background', '#cdfecd'); // adds background to visible #idd $('#idd:hidden').show('slow').css('color', 'blue'); // shows the hidden #idd and and adds color }); });
$('selector').toogle('duration');- "duration" - (optional) indicates the speed of show/hide effect. It can be the strings "fast" and "slow", or a number that indicates the speed in milliseconds.
$('selector').toogle('duration', function() { // code to execute });
<script type="text/javascript"><!-- $(document).ready(function() { // when click on the tag with id="btn" $('#btn').click(function() { // change the state of the "#idd" $('#idd').toggle(800, function() { // change the button text according to the state of the "#idd" if ($('#idd').is(':visible')) { $('#btn').text('Hide'); } else { $('#btn').text('Show'); } }); }); }); --></script> <div id="idd">Content that will be hidden and displayed.</div> <button id="btn">Hide</button>The code above changes the state (show/hide) of the <div> with id="idd", then uses the is(':visible') instruction to check if this DIV is visible or not, and accordind to its state changes the text in the button.
<table><tr> <th>Title 1</th> <th>Title 2</th> </tr></table>
.some_class { line-height: 150%; }
document.getElementById("id_button").onclick = function(){ window.open("http://coursesweb.net/"); }
$ar_dir = scandir("dir_name"); var_export($ar_dir);