0

This is a simple one for JS programmers. Base on this demo, https://codepen.io/gschier/pen/jkivt

I want 'The pen is simple.' to be 'The pen issimple.' To remove the space after 'is'.

I tried different areas with no luck. I only know CSS and HTML but not so much JS.

Of course this doesn't make sense with this demo example, I want to start it with an alphabet to make a sentence, for example

<h1>A
  <span
     class="txt-rotate"
     data-period="2000"
     data-rotate='[ " great day.", "pple.", "wesome.", " shinny diamond."]'></span>

With the current JS result, I get "A great day.", "A pple.", "A wesome.", "A shinny diamond." Please advise how do I remove the extra space. Thank you.

1
  • 1
    Remove all whitespace between "A" and the start of the span in the source code. Commented Jun 14, 2021 at 4:10

3 Answers 3

1

Try removing space / new line after A

<h1>A<span
     class="txt-rotate"
     data-period="2000"
     data-rotate='[ " great day.", "pple.", "wesome.", " shinny diamond."]'></span>

Working Demo

https://codepen.io/aswinkumar863/pen/NWpEygj

Sign up to request clarification or add additional context in comments.

Comments

0

you can use replace(/ +/g, ' ') remove multiple space

Comments

0

There are multiple solutions, for me the easiest and most convenient is just like below.

     $(document).ready(function(){
     var value=$(".txt-rotate").attr('data-rotate');
     val_array=JSON.parse(value);
     var array = val_array.map(function (el) {
    return el.trim();
        });
        array = '\'' + array.join('\',\'') + '\'';
        array="["+array+"]";
    
     $(".txt-rotate").attr('data-rotate',array);
     });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>A
  <span
     class="txt-rotate"
     data-period="2000"
     data-rotate='[ " great day.", "pple.", "wesome.", " shinny diamond."]'></span>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.