I'm new to jQuery. I'm taking a course and was given a test project, but I have no idea what to do. I'm just asking for someone to help me with an understanding. Here are the requirements:
Here is what I tried:
$(document).ready(function() {
// site code
for (var i=0; i<10; i++)
{
//jQuery factory
$("body").appendTo("<a href=">"+i+</>")
}
});
Here is the HTML section:
<body>
<div id="wrap">
<ul id="navleft"></ul>
<ul id="navright"></ul>
</div>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
I don't want answers, but a push in the right direction. I need a tutor, but they are so expensive and my teacher is never to be found, so I'm seeing if someone wouldn't mind helping.
jQuery is a lightweight, "write less, do more", JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
And that brings the question: is it worth learning jQuery in 2022? It's good to know jQuery and there are still use cases for it. However, you should not spend a lot of time learning it. jQuery should not be your focus this year.
jQuery is still very popular there; it works and it's simple, so people don't feel the need to stop using it.” jQuery will continue to be a part of WordPress for some time to come, if for no other reason that it would be difficult to remove it without breaking backward compatibility.
The jQuery starts its code execution from the $(document). ready() function which is executed whenever the whole HTML DOM is loaded and is totally rendered by the browser, so that the event handlers work correctly without any errors. This $(document).
you have both logical and syntax errors. Make sure your statements end with a ';
'
I think you are confused of how the $()
works. In simple terms, you can put in the $()
whatever you want to select from the page. So you are doing $('body')
, which tells jquery, "hey give me back all of the elements that are tagged <body>
", which is of course just the one.
Your assignment wants you to 'appendTo' the 'navleft' id. So what would you want to select from the page? Please note that to lookup an Id using $()
you should do $("#id")
now for appendTo, you assignment says to append a <li>
, however you are appending something else.
You should append EXACTLY what it says to append. <li><a>..<a/><li/>
The last traversing requirement you should have enough to do yourself. Just remember that $() will select all items that you tell it to, so what do you need to select to apply a color to all the anchors?
Aside from the obvious syntax errors in your post, I would look at the documentation for appendTo
and append
.
... and then swap round "body"
and "<a href=">"+i+</>"
You can track down syntax errors and runtime exceptions by using the Web Tools bundled with your browser. In most browsers (Chrome, FireFox) access these via F12 on your keyboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With