Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help to create shorter code

  1. #1
    Junior Member
    Join Date
    Feb 2023
    Location
    Netherlands
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Help to create shorter code

    Hello there ,

    I am creating a website about the periodic table of elements and want to use Java with it.
    The element needs to turn red when pressed and thats working.
    I have 118 elements who needs that function.
    Is there a shorter way to that instead of having 118 functions doing this?


    <td class="lanthaniden fblok" id="Lu" onclick="activeerLu()">71<br>Lu</td>

    function activeerCn(){

    document.getElementById("copernicium").style.displ ay = 'block';
    document.getElementById("Cn").style.backgroundColo r = "red";

    }

    Thank you in advance.

    Greetings,

    Tim

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help to create shorter code

    Javascript is not the same as Java.
    Try asking your questions on a forum for Javascript.

    Often a loop with the unique data in an array can be used vs 118 separate lines of code.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How many instances of class A does the following code create
    By tornado in forum Object Oriented Programming
    Replies: 4
    Last Post: July 3rd, 2014, 10:12 PM
  2. video game project (shorter methods required) HELP!!
    By copeg in forum What's Wrong With My Code?
    Replies: 9
    Last Post: April 1st, 2013, 11:29 PM
  3. [SOLVED] Create an executable (.jar or .exe) using code
    By nosxlimit in forum Java Theory & Questions
    Replies: 6
    Last Post: May 31st, 2012, 11:55 PM
  4. How can I make this shorter
    By mike2452 in forum The Cafe
    Replies: 2
    Last Post: August 7th, 2011, 10:58 PM