Ahora conoce tres formas de apuntar elementos: por tipo: <code>$("button")</code> , por clase: <code>$(".btn")</code> , y por id <code>$("#target1")</code> .
Aunque es posible agregar varias clases en una sola llamada <code>.addClass()</code> , las agregaremos al mismo elemento de <em>tres maneras diferentes</em> .
Usando <code>.addClass()</code> , agregue solo una clase a la vez al mismo elemento, de tres maneras diferentes:
Agregue la clase <code>animated</code> a todos los elementos con el <code>button</code> tipo.
Agregue la clase <code>shake</code> a todos los botones con la clase <code>.btn</code> .
Agregue la clase <code>btn-primary</code> al botón con id <code>#target1</code> .
<strong>Nota</strong><br> Solo debes apuntar a un elemento y agregar solo una clase a la vez. En total, sus tres selectores individuales terminarán agregando las tres clases <code>shake</code> , <code>animated</code> y <code>btn-primary</code> a <code>#target1</code> .
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?button\s*?(?:"|")/gi), "Use the <code><sectionid='tests'>
```yml
tests:
- text: 'Use the <code>$("button")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?button\s*?(?:"|")/gi), "Use the <code>$("button")</code> selector.");'
- text: 'Use the <code>$(".btn")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?\.btn\s*?(?:"|")/gi), "Use the <code>$(".btn")</code> selector.");'
- text: 'Use the <code>$("#target1")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?#target1\s*?(?:"|")/gi), "Use the <code>$("#target1")</code> selector.");'
- text: Only add one class with each of your three selectors.
testString: 'assert(code.match(/addClass/g) && code.match(/addClass\s*?\(\s*?("|")\s*?[\w-]+\s*?\1\s*?\)/g).length > 2, "Only add one class with each of your three selectors.");'
- text: 'Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.'
testString: 'assert($("#target1").hasClass("animated") && $("#target1").hasClass("shake") && $("#target1").hasClass("btn-primary"), "Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.");'
- text: Only use jQuery to add these classes to the element.
testString: 'assert(!code.match(/class.*animated/g), "Only use jQuery to add these classes to the element.");'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?\.btn\s*?(?:"|")/gi), "Use the <code><sectionid='tests'>
```yml
tests:
- text: 'Use the <code>$("button")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?button\s*?(?:"|")/gi), "Use the <code>$("button")</code> selector.");'
- text: 'Use the <code>$(".btn")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?\.btn\s*?(?:"|")/gi), "Use the <code>$(".btn")</code> selector.");'
- text: 'Use the <code>$("#target1")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?#target1\s*?(?:"|")/gi), "Use the <code>$("#target1")</code> selector.");'
- text: Only add one class with each of your three selectors.
testString: 'assert(code.match(/addClass/g) && code.match(/addClass\s*?\(\s*?("|")\s*?[\w-]+\s*?\1\s*?\)/g).length > 2, "Only add one class with each of your three selectors.");'
- text: 'Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.'
testString: 'assert($("#target1").hasClass("animated") && $("#target1").hasClass("shake") && $("#target1").hasClass("btn-primary"), "Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.");'
- text: Only use jQuery to add these classes to the element.
testString: 'assert(!code.match(/class.*animated/g), "Only use jQuery to add these classes to the element.");'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?#target1\s*?(?:"|")/gi), "Use the <code><sectionid='tests'>
```yml
tests:
- text: 'Use the <code>$("button")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?button\s*?(?:"|")/gi), "Use the <code>$("button")</code> selector.");'
- text: 'Use the <code>$(".btn")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?\.btn\s*?(?:"|")/gi), "Use the <code>$(".btn")</code> selector.");'
- text: 'Use the <code>$("#target1")</code> selector.'
testString: 'assert(code.match(/\$\s*?\(\s*?(?:"|")\s*?#target1\s*?(?:"|")/gi), "Use the <code>$("#target1")</code> selector.");'
- text: Only add one class with each of your three selectors.
testString: 'assert(code.match(/addClass/g) && code.match(/addClass\s*?\(\s*?("|")\s*?[\w-]+\s*?\1\s*?\)/g).length > 2, "Only add one class with each of your three selectors.");'
- text: 'Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.'
testString: 'assert($("#target1").hasClass("animated") && $("#target1").hasClass("shake") && $("#target1").hasClass("btn-primary"), "Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.");'
- text: Only use jQuery to add these classes to the element.
testString: 'assert(!code.match(/class.*animated/g), "Only use jQuery to add these classes to the element.");'
```
</section>#40"#target1")</code> selector.");'
- text: Solo agrega una clase con cada uno de tus tres selectores.
testString: 'assert(code.match(/addClass/g) && code.match(/addClass\s*?\(\s*?("|")\s*?[\w-]+\s*?\1\s*?\)/g).length > 2, "Only add one class with each of your three selectors.");'
testString: 'assert($("#target1").hasClass("animated") && $("#target1").hasClass("shake") && $("#target1").hasClass("btn-primary"), "Your <code>#target1</code> element should have the classes <code>animated</code>‚<code>shake</code> and <code>btn-primary</code>.");'
- text: Solo use jQuery para agregar estas clases al elemento.
testString: 'assert(!code.match(/class.*animated/g), "Only use jQuery to add these classes to the element.");'