Note that there are some explanatory texts on larger screens.

plurals
  1. POa selector which has this selector together with a class selector
    text
    copied!<p>Here is an analogy of my problem(a selector which has this selector together with a class selector):</p> <p>Let say that I selects all yellow(classes) div elements in a arbitrary HTML document. And I want each to check if the attribute is yes = 1. If the attribute 'yes' equals '1', then I want the child with class 'blue' have the attribute 'no' equals '1';</p> <pre><code>$('div .yellow').each(function(){ if($(this).attr('yes') == 1){ $(this '.blue:first-child').attr('no', 1);//This line needs to be fixed } }); </code></pre> <p>I know that the line <code>this.getElementsByClassName('blue')[0]</code> fixes this problem. But in my real problem (not this analogy) I want to use addClass and removeClass which only functions with jQuery objects. It is to cumbersome to use other functions than addClass and removeClass.</p> <p>UPDATE:</p> <p>Here is a code snippet from my real problem. I got some problem with "this" in javascript.</p> <p>I want a invited button to have the className visible when I click on it. The button lies within a div element with className 'box'. I know that there are problem with 'this' on the code snippet. But I want the button and not the box to change to visible</p> <pre><code>$('.Box').each(function(){ if($(this).attr('hasButton') != 1){ var invite = document.createElement('div'); invite.className = 'invite invisible'; invite.innerHTML = 'invite'; $(this).attr('hasButton', 1); this.appendChild(invite); invite.addEventListener('mouseover', function(event){ $('.invite', this).removeClass('invisible');//this line is not functioning $('.invite', this).addClass('visible');//neither this }, false); } }); </code></pre> <p>Ok solved it. I passed an element as attribute instead of classSelector.</p> <pre><code>$(invite).removeClass('invisible'); $(invite).addClass('visible'); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload