Monday 15 August 2011

warnings - RubyMine Waring Message - "Duplicated jQuery selector" -


I've added some simple javascript / jquery code in my Rail App that is ready to display the following warning:

  "Duplicate jQuery Selector".   

The environment gives me additional information about the warning message:

Checks that the jQuery selectors are used efficiently, this descendant selectors Suggests dividing which are already placed before the ID selector and warn about duplicated selectors who can be cached.

The code is very simple and I have been using it for years to check whether the element is provided, if it is not found, the element is added to the page: < / P>

  if ($ ('# error'). Length == 0) {$ ('& lt; span class = "error" id = "error" & gt;' + error_message + ' & Lt; / span & gt; ') .inertAfter (' # element '); } And {$ ('# Error'). Html (error_message); }   

The environment is giving me the error above for the following line:

  $ ('# error'). Length == 0   

I used it for a long time but see it again, is it a way to rewrite it, the only thing I have found is the use of the bus To do:

  $ ('# error'). Length   

But the environment shows me a single warning.

Is it really optimized and I am not using it properly or can the result of some internal misconception from the rules of the environment?

There is nothing wrong with the wrong or slow jQuery syntax of the warning selector I am using the same selector and the RubyMin environment is saying that it can be customized in terms of this selector: