Piotr Wu
Piotr Wu

Reputation: 1362

Simple jQuery plugin - reference error?

I'm writing simple jQuery plugin and it should search all .camp_row on the page and everywhere when it find .log.active, it should change its border.

$.fn.filtruj = function(){
    $(this).on('click', function(){
        var that = $(this);
        $('.camp_row').each(function(){
            $(this).find(that).css('border','10px solid orange');
        }); 
    })
}

$('.log.active').filtruj();

The problem is, it wor on only one result. I think that's because "that" refer to a specific .log.active' but no all .log.active.

Upvotes: 0

Views: 48

Answers (1)

Luca Rainone
Luca Rainone

Reputation: 16468

If I understand the question, you should pass the selector in constructor, then:

$.fn.filtruj = function(selector){

  $(this).on('click', function(){
    var that = $(this);

    $('.camp_row').each(function(){
        $(this).find(selector).css('border','10px solid orange');
    }); 
  })
}

$('.log.active').filtruj('.log.active');

Upvotes: 1

Related Questions