From the course: jQuery Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Solution
(lighthearted tone) - [Narrator] For my solution, I used the wrap function, that we say earlier in the course, to create a new link tag around each of the images in the product section. So, let's walk through the code and I'll explain how I did this. First, remember that part of the challenge was that we needed to pass two query string parameters to to product.html page. The first was the product name, and the second was the product ID. So, my code starts by using a selector expression to get all of the list item tags that contain each product. I then use the children function to get the h2 tag inside the list item and then call the text function on that h2 to get the product name. Since this string is going to be passed as part of a URL, I need to call the browser's encodeURIcomponent function to convert any characters that aren't allowed to appear in URLs. For the product ID, I just need to get the value of the data attribute that is on the list item tag itself. And then again, I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.