-2

Espero que esta mensagem os encontre bem.

Possuo o um código jquery que realiza buscas em tabela em tempo real. Este código faz buscas nesta tabela pelos valores das células, mas preciso que ele busque ao mesmo tempo por valores e valores do atributo title.

Exemplo se eu possuir o nome de uma empresa na tabela, ele encontrará esta empresa, todavia, se eu possuir a logo da empresa o nome dela estará no atributo TITLE e não como valor da célula. Preciso que este código busque por ambos, tanto as empresas que só possuem o nome registrado e também as que possuem logo na tabela, mas que o nome está no TITLE.

Já antecipando os meus agradecimentos, segue o código abaixo.

Forte abraço a todos!

<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>

<script>
    $(document).ready(function() {
        // Setup - add a text input to each footer cell
        $('#example tfoot th').each(function() {
            var title = $(this).text();
            $(this).html('<input type="text" placeholder="Search ' + title + '" />');
        });

        // DataTable
        var table = $('#example').DataTable({
            initComplete: function() {
                // Apply the search
                this.api().columns().every(function() {
                    var that = this;

                    $('input', this.footer()).on('keyup change clear', function() {
                        if (that.search() !== this.value) {
                            that
                                .search(this.value)
                                .draw();
                        }
                    });
                });
            }
        });

    });
</script>

1 Resposta 1

1
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
 $(document).ready(function(){  $("p[title|='Tomorrow']").css("background-color", "yellow");});  
</script>
</head>
<body>
<p title="Tomorrow">This is a paragraph.</p>
<p title="tomorrow">This is a paragraph.</p>
<p title="Tom">This is a paragraph.</p>
<p title="See You Tomorrow">This is a paragraph.</p>
<p title="Tomorrow-the day after today">This is a paragraph.</p>
<p>This selector selects all elements with a title attribute value equal to 'Tomorrow', or starting with 'Tomorrow' followed by a hyphen.</p>
</body>
</html>

Neste trecho é que tá o "segredo" da coisa

$(document).ready(function(){  $("p[title|='Tomorrow']").css("background-color", "yellow");});  

Ai eu consigo procurar a tag p e com um nome title específico e adicionar o background amarelo no elemento cujo o title é "Tomorrow", acho que é isso que quer.

Edit 1: você pode substituir também, e outro exemplo disto é este abaixo

<!DOCTYPE html>
<html>
<head>
    <title>Esconder titulos</title>
    <script type="text/javascript" src="script.js"></script>
</head>
<body>
    <input type="text" name="texto" id="texto">
    <button id="btn">Aplicar Titulo</button>
</body>

Script.js:

document.addEventListener('DOMContentLoaded',function() {
document.querySelector('#btn').addEventListener('click', function() {
    let text = document.querySelector('#texto').value;
    document.title = text;
});
});

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .