Explode in Jquery

0

I'm still having difficulties in Jquery, on the face of it I'm bringing a value from the Mysql database:

<div id="cod_<?php echo $jmValor->IdCodUsuarios; ?>">Nome do usuário</div>

But I need to type what happens with the PHP explode (), ie, remove the cod _ and leave only the value coming from the bank. So I did it this way:

var id = valor.split('cod_');
var valor = document.getElementById(id);
$(".conteudoChat").load("chat/?convidar=s&Key="+valor);

What I need is to get the value from the database, put the value in the div.

Thank you!

    
asked by anonymous 23.04.2015 / 17:03

1 answer

2

Live!

I think this is what you want. It will look for all the div's that have an "id" that starts with "cod_" and inserts in the contents of the div that follows the prefix "cod _".

$('[id^="cod_"]').each(function() {
    $(this).text($(this).attr('id').split("_")[1]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="cod_0001"></div>
<div id="cod_0002"></div>
<div id="cod_0003"></div>
<div id="cod_0004"></div>
<div id="cod_0005"></div>
    
23.04.2015 / 17:16