Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Learning Aids/Tools 2 years ago
Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
var img = document.getElementById('myImg'); var modalImg = document.getElementById("img01"); var captionText = document.getElementById("caption"); img.onclick = function(){ modal.style.display = "block"; modalImg.src = this.src; modalImg.alt = this.alt; captionText.innerHTML = this.alt; }
#myImg { border-radius: 5px; cursor: pointer; transition: 0.3s; }
id="myImg" src="imageone.jpg" alt="Image one" > id="myImg" src="imagetwo.jpg" alt="Image two" >
So the above snippet is used in the modal image css3 tutorial. I understand i cannot have more than one tags with the same ID which is why the code online works with one image. After researching i know i have to use a dyamic ID with JS.
var img = document.getElementById('myImg');
The previous JS line is what i need to change.
How does one dynamically change getElementById? So that i can use more then one with differentr src images?
Research shows Using a Tag selector or a class selector is inappropriate.
Any help documents to aid in my learning will be great as well.
So i made some nice progress with the css and stuff and it looks great. Now my next step is to use existing alts to include text when the modal appears. Below is the existing js line i had already
var captionText = document.getElementById("caption");
Now below is the html i will use when calling alt so that each image has its own alt text appearing under the modal pop up
I've tried it and doesnt seem to work, could it be my formatting in the css?
f there's a collection of elements that need to be processed the same, it's best to use the classattribute to target them.
class
Instead of targeting one element with: document.getElementById, you get a NodeList, which is a collection of elements, using document.getElementsByClassName or document.querySelectorAll.
document.getElementById
NodeList
document.getElementsByClassName
document.querySelectorAll
Then, you need to loop through these elements and use the code you've already written.
Here's an example:
var imgs = document.getElementsByClassName('myImg'); for (var i = 0; i < imgs.length; i += 1) { var img = imgs[i]; img.onclick = function() { // your on click stuff }; };
Don't forget to change the HTML to: class="myImg" src="imageone.jpg" alt="Image one" >
class="myImg" src="imageone.jpg" alt="Image one" >
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 9 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.