Похоже, что ни element.textContent, ни element.innerText не работают.
HTML:
Код: Выделить всё
Test Heading
Awesome video and music. Thumbs way up. Love it. Happy weekend to you and your family. Love, Sasha
fool("body");
Код: Выделить всё
jQuery.fn.justtext = function(text) {
return $(this).clone()
.children()
.remove()
.end()
.text();
};
function fool(el) {
reverse(el);
function reverse(el) {
$(el).children().each(function() {
if($(this).children().length > 0) {
reverse(this);
if($(this).justtext() != "")
reverseText(this);
} else {
reverseText(this)
}
});
}
function reverseText(el){
var text = el.textContent;
var frag = text.toString().split(/ /);
var foo = "";
var punctation_marks = [".",",","?","!"," ",":",";"];
for(i in frag){
if(punctation_marks.indexOf(frag[i]) == -1)
foo += actualReverse(frag[i],punctation_marks) + " ";
}
el.textContent = foo;
}
function actualReverse(text,punctation_marks) {
return (punctation_marks.indexOf(text.split("")[text.split("").length-1]) != -1)?text.split("").slice(0,text.split("").length-1).reverse().join("") + text.split("")[text.split("").length-1] : text.split("").reverse().join("");
}
}
Представьте себе следующий HTML< /p>
Код: Выделить всё
Last visit was: Sat Mar 31, 2012 10:50 am
[url=./search.php?search_id=unanswered]View unanswered posts[/url] | [url=./search.php?search_id=active_topics]View active topics[/url]
Подробнее здесь: https://stackoverflow.com/questions/995 ... javascript
Мобильная версия