tags:

views:

132

answers:

2

I have the following markup:

<div id ="selectable1">
<span id="layer6">
here are some words that needs to be splited
<span class="good">this should not be splitted<span>
this should be splitted
<span class="good">and this should not be spited<span>
</span>
</div>

I am trying to write a function that will split only the words that do not have class "good". I am using this:

var words = $("#selectable1 span.cica").text().split(" ");
var text = words.join("</span><span class='drag col'>  ");
$("#selectable1 span.cica").html("<span class='drag col'>" + text + "</span>");

...but this is splitting all my words and I need the "good" class not to be splitted and not to be added to the var text - join.

I hope that I had explained well what I want to do here, I know that this can be confussing.

Thanx for your help

+4  A: 

Update based on comments. Since you'r wrapped in a span, the selector is going a bit crazy, do this instead:

var span = $("#selectable1>span.cica").clone();
span.find(".good").remove();
var words = span.text().split(" ");
var text = words.join("</span><span class='drag col'>  ");
Nick Craver
I see your shwartz is as big as mine...
hunter
@Hunter - Hah, awesome movie
Nick Craver
I've tryed this:var words = $("#selectable1 span.cica:not(.good)").text().split(" ");var text = words.join("</span><span class='drag col'> ");$("#selectable1 span.cica").html("<span class='drag col'>" + text + "</span>");But it does not work.I've made an edit to my source adding the line that actually execute the variabiles
Mircea
@Mircea - What's the `.cica` for?
Nick Craver
@Nick there are several spans in that #selectable container. The one that is active have the class .cica. When someone clicks on a span it becomes active and gets class cica
Mircea
your code should work but this code just takes all the text including the "good" class one:$("#selectable1 span.cica").html("<span class='drag col'>" + text + "</span>");
Mircea
@Mircea - I see what you mean now, I updated the answer, you should be all set now.
Nick Craver
@Nick, it does keep the good classes but duplicates the whole text. Its better and I may be able to fix it. I am really sorry but I have to go out for 2 hours. I will post the solution, if I can fix it, later on today.Thank you
Mircea
+2  A: 
var words = $("#selectable1 span:not(.good)").text().split(" ");
var text = words.join("</span><span class='drag col'>  ");

That might work...

hunter