John Magnolia
John Magnolia

Reputation: 16793

jQuery - not selecting a class that begins with 'tinymce'

What is wrong with this code:

$('input[maxlength],textarea[maxlength]').not("[class^='tinymce']").each(function() {

I am trying to select:

Upvotes: 0

Views: 103

Answers (3)

Roman
Roman

Reputation: 6428

http://jsfiddle.net/z5Wsk/

this code selects the textareas that don't have a class which begins with "tinymce".

$('input[maxlength],textarea[maxlength]').filter(function() {
    if($(this).attr('class')) {
        return null == $(this).attr('class').match(/\btinymce[a-z0-9_\-]*\b/i);
    }
    return true;
}).each(function() {
    //your part
});

​example: an element with class="another tinymceFOO" is not selected (while the accepted answer would select it).

Upvotes: 0

SeanCannon
SeanCannon

Reputation: 77966

Does it have to start with tinymce or just contain the class tinymce?

​$('input,textarea').filter(function(){
    return(!$(this).hasClass('tinymce'));
}).filter(function(){
    return($(this).attr(​​​​​​​​​​​​'maxlength'));
})

http://jsfiddle.net/Fqg5Y/1/

Upvotes: 1

Chris Dixon
Chris Dixon

Reputation: 9167

This code works for me...

http://jsfiddle.net/xJCCT/1/

Only one "hello" is outputted.

Upvotes: 3

Related Questions