There is a code:
<div id="block"> <span></span> </div> $('#block').click(function(){ $(this, 'span').addClass('content'); }); What am I doing wrong? Does not work. It is necessary to add a class for the span.
There is a code:
<div id="block"> <span></span> </div> $('#block').click(function(){ $(this, 'span').addClass('content'); }); What am I doing wrong? Does not work. It is necessary to add a class for the span.
Clearly, I did not immediately understand what it was about and what was not working.
You incorrectly use a sample, according to the documentation $(выражение, контекст) , that is, this and 'span' should be swapped.
$('#block').click(function(){ $('span', this).addClass('content'); }); Is it not so? Judging by the question, inside only span?
$('#block').click(function(){ $(this).children().addClass('content'); }); And with the switch once or twice:
$('#block').click(function(){ if( $(this).children().hasClass('first')) { $(this).children().addClass('second'); } else { $(this).children().addClass('first'); } }); Source: https://ru.stackoverflow.com/questions/397008/
All Articles