Jump to content

Recommended Posts

Posted (edited)

boa tarde

estou aqui com uma duvida em usar o each

tenho uma listagem onde cada linha ao carregar irá abrir uma pagina nova, cada linha tem um atributo associado

gostaria que no jquery ao carregar nessa linha ele soubesse qual o atributo

tenho feito assim

$(msg).each(function(){
	 for (var i = 0; i < this.attributes.length; i++) {
		 console.log(' Valor:' +this.attributes["data-id"].nodeValue);
		 var id=this.attributes["data-id"].nodeValue;

	 };
 //return false;
	 });

só que ele assim dá-me a listagem de todos os atributos, se coloco o return false ele só me dá o primeiro atributo...

sei que está a faltar alguma forma de poder tirar deste each apenas o valo clicado

obrigado

desde já pela ajuda

Edited by nmoa
Posted
var msgListing = $('.panel > #message-table > tbody > tr > td');
   var msg= $('.panel > #message-table > tbody > tr ');

	 msgListing.not(":first-child").on('click', function (e) {
	  e.stopPropagation();
	  e.preventDefault();

	 $(msg).each(function(){
	 for (var i = 0; i < this.attributes.length; i++) {
		    console.log(' Valor:' +this.attributes["data-id"].nodeValue);
		    var id=this.attributes["data-id"].nodeValue;
		    teste(id);

	    };
    //return false;
	 });

mais completo

Posted

da o erro

Valor: undefined

aproveito para deixar aqui o codigo php

$passagem= mysql_query ("SELECT * FROM passagem limit $inicio, $qnt ");
			    $passagem2= mysql_query ("SELECT * FROM passagem ");
			    $total_registros = mysql_num_rows($passagem2);
$pags = ceil($total_registros / $qnt);
while ($passa=mysql_fetch_array($passagem)){
   $emissor = mysql_query ("SELECT * from comercial where id_comercial=".$passa["id_emissor"]."");
   $emi = mysql_fetch_array($emissor);

   $comercial = mysql_query ("SELECT * from comercial where id_comercial=".$passa["id_comercial"]."");
   $comerc = mysql_fetch_array($comercial);
   echo' <tr class="message-unread" data-id="'.$passa["id_passagem"].'">
			    <td class="hidden-xs">
				  <label class="option block mn">
				    <input id="escolha" type="checkbox" name="mobileos" value="FR"><span class="checkbox mn"></span>
				  </label>
			    </td>				   
			    <td>'.$emi["nome"].'</td>				   
			    <td>'.$comerc["nome"].'</td>
			    <td class="text-center fw400">'.$passa["data"].'</td>
			  </tr> ';

}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.