Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:05:45+00:00 2026-06-03T18:05:45+00:00

Below is the javascript I have for my page: window.onmouseover = function(){ var body

  • 0

Below is the javascript I have for my page:

    window.onmouseover = function(){
        var body = document.getElementsByTagName("body")
        var h1 = document.getElementsByTagName("h1");
        var a = document.getElementsByTagName("a");
        var p = document.getElementsByTagName("p")
        for(var j = 0; j < p.length; j++) {
            body[j].style.fontFamily = "helvetica";
            body[j].style.backgroundColor = "rgb(250, 250, 240)"
            p[j].style.fontFamily = "courier";
            a[j].onclick = function() {
                this.style.backgroundColor = "Black"
            }
        }
    }

I have one h1 element, one a element, and 10 p elements. For some reason, this code only changes the font of the first p element, although everything else works fine? Why is this and how can I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:05:47+00:00Added an answer on June 3, 2026 at 6:05 pm

    If you have only one a element and (of course) only one body you cannot iterate over 10 of them. This causes an error on the second iteration of the cycle. Use this code instead.

    window.onmouseover = function(){
        var body = document.getElementsByTagName("body")
        var h1 = document.getElementsByTagName("h1");
        var a = document.getElementsByTagName("a");
        var p = document.getElementsByTagName("p")
    
        body[0].style.fontFamily = "helvetica";
        body[0].style.backgroundColor = "rgb(250, 250, 240)"
        a[0].onclick = function() {
            this.style.backgroundColor = "Black"
        }
    
        for (var j = 0; j < p.length; j++) {
            p[j].style.fontFamily = "courier";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have JavaScript of ajax uploader as below; $(document).ready(function(){ var qwerty = $('#qwerty').val(); $('#demo1').ajaxupload({
I have Javascript as below: <script type="text/javascript" language="javascript"> function redirectToPrevious(abcURL) { window.location.replace(abcURL); } function
I have a PHP code: if($billing_total>$limit_to_send){ echo '<script type=text/javascript> window.onload = function() { alert(Sorry,
I have this Javascript below using jQuery that shows a div on a page
I have the below code on one page: <div id=prodoneid class=prodcls> <a href=javascript:void(changeIt('big.png', 'pagewrapid')());>
I have a javascript function below where it removes an appended file name from
I have a JavaScript function below where it displays a message after file uploading
I have a javascript function below where when a file has finished uploading, it
I have this javascript code below that uses jquery, it is suppoed to be
I have a dialog box, created with the code javascript and HTML generated below.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.