locked
write script code on click without Script tag RRS feed

  • Question

  • User2062956768 posted

    friends;

    i have input type button with Onclick  event

    I want to change backcolor of div element Without using Script TAG <Script>

    for example

    onclick ="getelementbyID.backcolor=anycolor"

    is this possible using javaScript

    or run any javaScript Command 

    Tuesday, September 24, 2019 10:18 PM

Answers

  • User-719153870 posted

    Hi mrzoz,

    I want to change backcolor of div element Without using Script TAG <Script>

    for example

    onclick ="getelementbyID.backcolor=anycolor"

    is this possible using javaScript

    or run any javaScript Command 

    Yes, you can add similar js functions just right in its onclick event.

    Please refer to below code:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <input type="button" value="Change div color" onclick="document.getElementById('demo').style.backgroundColor='red';" />
            </div>
            <div id="demo" style="width:200px; height:200px;background-color:blue;">
            </div>
        </form>
    </body>
    </html>

    Here's the result:

    Best Regard,

    Yang Shen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 25, 2019 1:33 AM