tags:

views:

427

answers:

3

Hi, 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("").join("</em><em>");
        $("#selectable1 span.cica").html(newSplit);

    });
    });
    </script>

Thank you.

A: 

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.

rahul
Yes, I need to have some nested EM tags. Once their attributes will be changed I will remove the em markup. I am looking into window.parent but I have no idea on how to use it.Thanx
Mircea
A: 

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>");
Mircea
+1  A: 

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'

djch