Changing a class search in jQuery for a word search

0

Sorry if I was not clear on my question. I'm starting with JS and jQuery and my question is this: in the code below, is there any way to instead search for classes, search for words?

when(function() {
    return jQuery != undefined && jQuery('.classe1, .classe2').length;
}) 
    
asked by anonymous 15.08.2017 / 20:23

1 answer

0

Hello,

To search by string in attribute, you can use the Attribute = Value selector.

Documentation: link

Example:

var texto1 = $('[class*="teste1"]').text();
var texto2 = $('[class*="teste5"]').text();
var texto3 = $('[class*="teste9"]').text();

$('#seletor-1').html(texto1);
$('#seletor-2').html(texto2);
$('#seletor-3').html(texto3);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pclass="teste1 teste2 teste3">Lorem ipsum sit dolor ommet 1</p>
<p class="teste4 teste5 teste6">Lorem ipsum sit dolor ommet 2</p>
<p class="teste7 teste8 teste9">Lorem ipsum sit dolor ommet 3</p>

<hr>

<p id="seletor-1"></p>
<p id="seletor-2"></p>
<p id="seletor-3"></p>

In this example,

15.08.2017 / 20:49