2

I would like to vertically align the text in div on the click on a button.

I am using php and jquery framework library.

This is what I am trying to ask:

Ex: "myname is xyz" (normal alignment)

Vertical alignment

Ex:
m
y

n
a
m
e
....

Please guide.

c69
  • 19,951
  • 7
  • 52
  • 82

2 Answers2

3

There are several possibilities for making stuff like this. One of the easiest approaches would be to insert a <br> tag after each letter...

HTML:

<div>foo bar</div>
<button>button</button>

JS:

var state, $div = $('div');
$('button').click(function(){
    if (!state) {
        $div.html($div.html().split('').join('<br>'));
        state = true;
    } else {
        $div.html($div.html().split('<br>').join(''));
        state = false;
    }
});

See:

http://jsfiddle.net/bkkK6/22/

Edit:

split/join if you like it more ... :D

conceptdeluxe
  • 3,753
  • 3
  • 25
  • 29
2

Use word-wrap property of css

 <script>
    $("button").click(function(){
    $("div").html($("div").html().split(" ").join("&nbsp;"));
    if($("div").width()==1)
    {
    $("div").width("100%");
    }
    else
    {$("div").width(1);
    }
    });</script>

DEMO

bugwheels94
  • 30,681
  • 3
  • 39
  • 60