i'm new to prototype framework and i'm trying to apply some functions to classes elements and not ids elements. This because I need to replicate every functions to various elements. If I apply them to ids elements, only one of those get involved.
So, this is my script running with ids elements:
function removing (){
$('element').remove();
var data = $('element').innerHTML;
var wanted_count = 50;
var output = cutHtmlString(data, wanted_count);
$('element').replace(output);
}
the script remove and element of two and, and cuts the remaining one (an html string) and replace it.
I tried this but doesn't work:
function removing (){
$$('element').remove();
var data = $$('element').innerHTML;
var wanted_count = 50;
var output = cutHtmlString(data, wanted_count);
$$('element').replace(outpu开发者_运维知识库t);
}
thanks for helping
'$$' returns an array, even if there happens to be only one result.
So you cannot apply functions such as remove() to the result of $$.
You probably want
$$('element').invoke('remove');
However, there is another problem: $$ takes a CSS rule, so $$('element'), though syntactically valid, would match only things matched by the CSS rule 'element' - i.e. DOM elements with tag 'element', and there aren't any in HTML.
If what you mean is all elements with class 'element', then the code is
$$('.element').invoke('remove');
精彩评论