How to change the text of a <span> element using Javascript without <span> disappearing?

I have a really simple question but it’s something I have not done before.

I have <span>↑</span> in my HTML:

<div class="button--up-down" data-type="up">

But I dont have <span>↑</span> in my JS:

var lastPageScroll = 0;
$(document).on('click', '.button--up-down', function () {
    var type = $(this).attr('data-type');
    var speed = 0; //ms

    if (type == 'up') {
        lastPageScroll = $("body,html").scrollTop();
        if (lastPageScroll > 0) $(this).attr('data-type', 'down').text('↓');
            scrollTop: 0
        }, speed);
    if (type == 'down') {
        $(this).attr('data-type', 'up').text('↑');
            scrollTop: lastPageScroll
        }, speed);
$(document).on('scroll', function () {
    var $button_up_down = $('.button--up-down');
    var type = $button_up_down.attr('data-type');

    if ($(window).scrollTop() > 150) {

        if (type == 'down') {
            $button_up_down.attr('data-type', 'up').text('↑');
    } else if (lastPageScroll == 0 || ($button_up_down.attr('data-type') == 'up' && $(window).scrollTop() < 150)) $button_up_down.removeClass("visible");

So I need to add <span>↑</span> to my JS but i am not sure how to add it without using innerHTML?

Sorry for the noob question.

94 thoughts on “How to change the text of a <span> element using Javascript without <span> disappearing?”

  1. Pingback: liquid keto diet
  2. Excellent goods from you, man. I have take into accout
    your stuff prior to and you are just extremely great. I really like what you’ve received right here,
    really like what you’re stating and the way wherein you
    assert it. You make it enjoyable and you still care for to stay it smart.
    I cant wait to learn far more from you. That is actually a wonderful web site.

  3. Hey there! I could have sworn I’ve been to this site before but after reading through some of
    the post I realized it’s new to me. Nonetheless, I’m definitely glad I found it and I’ll be bookmarking
    and checking back frequently!

  4. Its such as you learn my mind! You seem to grasp so much approximately this, like you wrote the e-book in it or something.
    I feel that you just could do with some % to pressure the
    message home a little bit, but instead of that, this is wonderful blog.

    A great read. I’ll definitely be back.

  5. We’re a group of volunteers and opening a new scheme in our community.
    Your web site offered us with valuable information to work on. You’ve done a formidable job and our
    whole community will be grateful to you.

  6. What i don’t realize is if truth be told how you are now not really much more
    neatly-favored than you may be now. You’re so intelligent.

    You recognize thus significantly with regards to this subject,
    made me personally consider it from so many various angles.
    Its like women and men aren’t involved until it is something to do
    with Lady gaga! Your own stuffs excellent. Always care for it up!
    quest bars quest bars

  7. Hello! This is my 1st comment here so I just wanted to give a quick shout out and tell you I genuinely enjoy reading
    through your blog posts. Can you suggest any other blogs/websites/forums that go over the same topics?
    Thanks for your time!

  8. Hello there, I discovered your blog via Google while looking for a similar matter, your web site
    got here up, it seems to be good. I have bookmarked it in my google bookmarks.

    Hello there, just become aware of your weblog via Google,
    and located that it is really informative. I’m going to be careful for brussels.
    I will be grateful should you proceed this in future.
    Numerous other folks shall be benefited out of your writing.

  9. Its like you read my mind! You appear to know so much about
    this, like you wrote the book in it or something.
    I think that you can do with a few pics to drive the message home a
    bit, but instead of that, this is wonderful blog.

    A fantastic read. I will certainly be back.

  10. Howdy! I could have sworn I’ve been to this web site
    before but after looking at some of the articles I realized it’s new to me.
    Anyways, I’m definitely happy I came across it and
    I’ll be bookmarking it and checking back often!

  11. Good day I am so glad I found your web site, I really found
    you by accident, while I was researching on Aol for something else, Nonetheless I am here now and would
    just like to say kudos for a marvelous post and a all round entertaining blog (I also love
    the theme/design), I don’t have time to read it all at the moment but I have bookmarked
    it and also included your RSS feeds, so when I have time
    I will be back to read much more, Please do keep
    up the awesome job.

  12. Hey! Someone in my Myspace group shared this site with us so I came to look it over.
    I’m definitely loving the information. I’m book-marking and will be tweeting this to
    my followers! Excellent blog and excellent style and design.

  13. Hi, I think your website might be having browser compatibility issues.
    When I look at your blog site in Safari, it looks
    fine but when opening in Internet Explorer, it has some
    overlapping. I just wanted to give you a quick heads up! Other then that, terrific blog!

  14. This design is incredible! You obviously know
    how to keep a reader amused. Between your wit and your videos, I
    was almost moved to start my own blog (well, almost…HaHa!) Excellent job.
    I really enjoyed what you had to say, and more than that, how you presented it.
    Too cool!

  15. Very nice post. I just stumbled upon your blog and wanted to say that I have truly enjoyed browsing
    your blog posts. After all I’ll be subscribing to your feed and
    I hope you write again very soon!

  16. I think this is among the such a lot significant info for me.
    And i’m satisfied reading your article. However wanna remark on some common issues, The web site taste is great, the articles is in reality great : D.
    Good activity, cheers

  17. Hi there! Someone in my Facebook group shared this site with us so I came to
    look it over. I’m definitely loving the information. I’m book-marking and will be tweeting this to
    my followers! Great blog and amazing design and style.

  18. I’m really enjoying the design and layout of your website.

    It’s a very easy on the eyes which makes it much more pleasant for
    me to come here and visit more often. Did you hire out a developer to
    create your theme? Superb work!

  19. Hello there! This is kind of off topic but I need some help from an established blog.
    Is it tough to set up your own blog? I’m not very techincal but I can figure
    things out pretty quick. I’m thinking about making my own but I’m not sure where to start.
    Do you have any tips or suggestions? Cheers

  20. I’m impressed, I must say. Seldom do I come across a blog
    that’s both equally educative and entertaining, and let
    me tell you, you’ve hit the nail on the head.
    The issue is something that too few people are speaking intelligently about.
    I’m very happy that I found this in my search for something concerning this.