I’ve posted a similar question regarding switching HTML text snippets (see JS Switch HTML content based on specific text included in h1 tag), for which the replies were hugely helpful. From these replies, I used the following code to change the HTML text snippet: I now wish to modify the code to change the img src depending on some text
Tag: if-statement
JS Switch HTML content based on specific text included in h1 tag
I’m quite new to javascript and have been searching for a solution with no joy. I want to switch the content of a certain p tag depending on if the H1 tag contains certain text. I aim to put this js in the of every page ready for when it’s needed. I have figured out that ‘if’ and ‘else if’
how to check if multiple list items has the class Name “valid”
I am working on a password validation process. when the password input in a Sign up page is clicked a list of requirement is shown And if the created password respect one of the requirements a “valid” className will be added to the li that will add additional styles to it. what I want to do next is to check
How to toggle the “src” attribute of an image without using an if-statement?
the problem is I want to change the src of img tag by using the button which executes if, else function. but I think my code is unprofessional and there is a better way to do the same job. Answer Here is another solution, wich is just 5 lines of JS. It uses if-else oneliners, to wich a detailed guide
Using HTML and Javascript to make a concrete supplies calculator – Takes a value of both ____m3 and a select option (mpa) to give a total price
This is my first time asking a question on Stack Overflow so apologies if I get something wrong. I am currently building a web calculator for a concrete company. Here are the details of the inputs: There is a form with the following inputs: Input 1: Cubic Meters (m3) Input 2: Strength Input 1 takes a value between 0.1 m3
Another way of implementing an If else statement for viewport check?
I am dealing with a simple premise that questions viewport and based on that i am returning different aspectRatios. Now, for some reason i always have else return as true and then millisecond later the viewport gets validated. The result is that i am picking 2 aspect ratios and that makes me download additional image, which presents as unnecessary. I
How can I detect if a var was passed and then block it from passing again?
I have a quick question, My project is a quick 4 option answers, With radio buttons and pictures displayed, Now I have the pictures and the answers stored in a text file, That way my JS detects what it reads and then passes it to HTML, Now I use this function to pick a random line: Now How would I
shorten if conditions in js
I want to shorten the conditions of a javascript if but I don’t know how I can achieve it code: I have the conditions defined in this way: I appreciate any help! 🙂 Answer You can remove all unnecessary parenthesis in your if condition: Other than that, there’s not really a clean, readable way to shorten your code.
how can i make all if statements in a loop ? in Javascript
i’ve already tried a for loop but I’m new to javascript so it’s all still hard for me. I am grateful for any help. It should increase values. here´s my code: and so forth. Answer
javascript: How to trigger an if statement when a variable equals a number in an array? [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 months ago. Improve this question Basically what I have is an array with these numbers: var songTimer = [0,12,49]. What I want to happen is that every time audio.currentTime(a built