开发者

jQuery text split and join, does not wrap the first letter

I have a function that splits each letter from a span text and wrap it into an em. It works but the first letter from the span is not wrapped. How can I wrap that letter also in em?

   <script>
    jQuery(document).ready(function(){
        $(".nsplit").live('click', function(){
        var newSplit = $("#selectable1 span.cica").text().split("").j开发者_开发问答oin("</em><em>");
        $("#selectable1 span.cica").html(newSplit);

    });
    });
    </script>

Thank you.


For the text "Test", the initial code:

$("#selectable1 span.cica").text().split("")

Would have produced an array ['T','e','s','t]

Calling join on the array inserts the separator between each array item, so you would end up with:

T</em><em>e</em><em>s</em><em>t

You then need to wrap the initial 'T' with a starting <em> and close off with a </em> on the final 't'


using window.parent you can get a reference to the parent of the iframe.

Is there anything that you want to achieve by nesting iframes? If yes, then you have to traverseup the tree using parent to get the topmost parent.


I've changed the code to something I found on jQuery examples and now it works. I can't figure it out why it did not work right the first time. Here is the new code if anyone have the same problem

  var words = $("#selectable1 span.cica").text().split("");
  var text = words.join("</em><em>");
  $("#selectable1 span.cica").html("<em>" + text + "</em>");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜