The forum of the forums

Would you like to react to this message? Create an account in a few clicks or log in to continue.
The forum of the forums
2 posters

    How to add a class to this javascript code?

    Starrain
    Starrain
    New Member


    Female Posts : 5
    Reputation : 1
    Language : Html | CSS

    Solved How to add a class to this javascript code?

    Post by Starrain January 17th 2016, 1:40 pm

    Hello! ^^
    I have just found this topic and this code:
    Code:
    <script type="text/javascript">document.write(_userdata.avatar)</script>
    I'd like to put this into a html page, but I was wondering if there is any possibility to give this code a class so that I can add CSS codes to it. I haven't had the chance to learn javascript yet, so it would be nice if someone could tell me how to add a class to the code ^^

    Greetings, Starrain





    Last edited by Starrain on January 19th 2016, 9:10 pm; edited 1 time in total
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: How to add a class to this javascript code?

    Post by Ange Tuteur January 18th 2016, 6:05 pm

    Hi @Starrain,

    document.write() can take any string of HTML and will parse it at run time. In answer to your question, you can concat the avatar variable between two HTML strings.
    Code:
    <script type="text/javascript">document.write('<span class="user_avatar">' + _userdata.avatar + '</span>')</script>

    If any questions let me know. Wink
    Starrain
    Starrain
    New Member


    Female Posts : 5
    Reputation : 1
    Language : Html | CSS

    Solved Re: How to add a class to this javascript code?

    Post by Starrain January 19th 2016, 9:09 pm

    It works! Thank you very much and have a nice day ^-^
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: How to add a class to this javascript code?

    Post by Ange Tuteur January 19th 2016, 9:50 pm

    You're welcome ^^

    Topic archived

    Have a good day. Smile

      Current date/time is November 11th 2024, 6:30 pm