How can I have multiple onClick events linked to one element in HTML? And can I have them change href's?

44,108

Just separate your commands with a semi-colon:

onClick="document.Awesome2.src='chicken.jpg'; document.furtherInstructions.href='ChickenText.html';">
Share:
44,108
Henry Edward Quinn IV
Author by

Henry Edward Quinn IV

Updated on May 17, 2020

Comments

  • Henry Edward Quinn IV
    Henry Edward Quinn IV almost 4 years

    I'm building a page for a company I'm interning for, and can't seem to figure this one out. The code you see below is just a simplified template, so that I don't give any information about the company away (and all the style attributes are in a separate document, so everything in the code is alright.

    What I'm having a problem with is making multiple onClick events work. For that matter, is using the onClicks in the comment tags even feasible? I want the text that says Further Instruction to have it's href path changed depending on the animal picture that's clicked.

    Also, I can't use any JavaScript, so please don't suggest the use of any. Happen to have any ideas?

    <div id="container">
        <div class="mainPicture">
            <img alt="" id="awesome" name="Awesome2" src="awesome.png" />
        </div>
        <div id="gallery">
            <ul class="popOut">
                <li>
                    <a href="DogText.html" target="AnimalInfo" onClick="document.Awesome2.src='dog.jpg'"> <!--onClick="document.furtherInstructions.href='DogText.html'">--> 
                        <img src="dog.jpg" alt="dog"><img src="dog.jpg" alt="dog" class="preview"> 
                    </a>
                </li>   
                <li>
                    <a href="CatText.html" target="AnimalInfo" onClick="document.Awesome2.src='cat.jpg'"> <!--onClick="document.furtherInstructions.href='CatText.html'">-->
                        <img src="cat.jpg" alt="cat"><img src="cat.jpg" alt="cat" class="preview"> 
                    </a>
                </li>   
                <li>
                    <a href="ParrotText.html" target="AnimalInfo" onClick="document.Awesome2.src='parrot.jpg'"> <!--onClick="document.furtherInstructions.href='ParrotText.html'">-->
                        <img src="parrot.jpg" alt="parrot"><img src="parrot.jpg" alt="parrot" class="preview"> 
                    </a>
                </li>       
                <li>
                    <a href="LizardText.html" target="AnimalInfo" onClick="document.Awesome2.src='lizard.jpg'"> <!--onClick="document.furtherInstructions.href='LizardText.html'">--> 
                        <img src="lizard.jpg" alt="lizard"><img src="lizard.jpg" alt="lizard" class="preview"> 
                    </a>
                </li>       
                <li>
                    <a href="HorseText.html" target="AnimalInfo" onClick="document.Awesome2.src='horse.jpg'"> <!--onClick="document.furtherInstructions.href='HorseText.html'">-->
                        <img src="horse.jpg" alt="horse"><img src="horse.jpg" alt="horse" class="preview"> 
                    </a>
                </li>       
                <li>
                    <a href="ChickenText.html" target="AnimalInfo" onClick="document.Awesome2.src='chicken.jpg'"> <!--onClick="document.furtherInstructions.href='ChickenText.html'">--> 
                        <img src="chicken.jpg" alt="chicken"><img src="chicken.jpg" alt="chicken" class="preview"> 
                    </a>
                </li>   
                <li>
                    <a href="DefaultText.html" target="AnimalInfo" class="center" onClick="document.Awesome2.src='awesome.png'"> <!--onClick="document.furtherInstructions.href='DefaultText.html'">-->
                        <p>Default Image</p>
                </a>
                </li>
            </ul>
            <div id="rightcol">
                <iframe src="DefaultText.html" title="Information About Animals" name="AnimalInfo" class="fixThisHeight">
                </iframe>
            </div>
            <div id="externalInstructions">
                <a href="DefaultText.html" name="furtherInstructions">
                    <p>Further Instructions</p>
                </a>
            </div>
        </div>
    </div>