Design comparison
Solution retrospective
PFewww ... this one was a real challenge... It took so long for me to display correctly the images and the small arrow icons... (which I know I didnt use the correct solution to display).
And, I did my first code in JS.. Quite hard I'd say! There's a problem when i click on the text do display the paragraph down, I need to click two times for it to work. I don't understand why.
Can someone help me to improve my code here? I do need it... Be indulgent, Im just starting coding... Thanks
[UPDATE] I used jQuery for the accordion effect, but how to turn the arrow down in this cas?
Any advice?
Community feedback
- @12KentosPosted over 2 years ago
Hey @neuyann,
Nice job on finishing this challenge especially with it being the first one you used Javascript on!
If you check out jQuery, I would suggest you keep working on learning vanilla Javascript as well. Yes jQuery is easier, but the better you know vanilla Javascript, the easier jQuery will be to use, and you will be able to do things people who only know how to use jQuery won't be able to do. ;)
As for the Javascript, have you heard about event listeners? If not I would suggest you look into them, as I was able to complete the challenge with the following Javascript.
`const faqs = document.querySelectorAll(".faq-card__text__container");
faqs.forEach((faq) => { faq.addEventListener("click", () => { faq.classList.toggle("active"); }); });`
copy and pasting this into your project wouldn't work, as my html is structured differently. However I'd be happy to help find some good places to learn more about event listeners, how they work and what not. Feel free to check out my solution to the project, and compare. :)
Keep up the great work!
Marked as helpful0 - @covstarPosted over 2 years ago
Have you tried using jQuery. It's much easier than vanilla JavaScript. For example if you want the paragraph to display on click:
HTML:
<div class ="first-paragraph"> <div class="first-heading> <p> your heading to be clicked on</p> </div> <div class="inner-content> <p> paragraph to show or hide on click</p> </div> </div>JavaScript:
$(document).ready(function (){ // Click on the heading to perform a function $('.first-heading').click(function (){
// Will slide the content up or down when clicked once $('.inner-content').slideToggle(); });
})
I hope this is helpful?
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord