tooltiperror
Super Moderator
- Reaction score
- 231
[CODE]I thought jQuery had a very ugly and confusing syntax, but when I figured it out, it's actually quite easy. The only thing that turned me off was that people started with examples and weird syntax, but I found out that the syntax makes sense when broken down.
First of all, you need to import jQuery. It would be mad to put jQuery inside of each HTML document, so you load it from a file in the same directory. Here we have it, it's pretty basic and you should already know how to do this, but in case you don't, here it is.
[CODE]
<html>
<head>
<script type="text/javascript" charset="UTF-8" src="jquery.js"></script>
</head>
<body>
</body>
</html>
$('p') // Select all paragraph elements
$('#banner') // Selects something with the Id "Banner"
$('*') // All elements on the page
$('p:first') // The first paragraph element
$('p:last') // The last paragraph element
$('p').hide();
$('p').hide('slow');
$('p').hide('slow',function(){/*Code to be executed after the paragraphs are hidden.*/});
$('p').hide('slow',function(){
$('p').show('slow',function(){
$('p').hide('fast');
});
});
$('p').click(function(){
$('p').hide('slow');
});
$('p').click
(
function()
{
$('p').hide('slow',function()
{
alert('Strange brace style is strange');
});
}
);
$(document).ready(function(){
$('*').show();
});
$('p').click(function(){
$('p').doSomething();
});
This will call doSomething on EVERY paragraph after you click ANY one paragraph.
You might want to change it to:
$('p').click(function(){
$(this).doSomething();
});
Yes, that is not a flaw, that's the tutorial?
Would you rather me use this?
$('p').click(function(){
var loc = $('p').find('a').attr('href');
window.location = loc;
});