Foros del Web » Programando para Internet » Javascript »

Obtener datos

Estas en el tema de Obtener datos en el foro de Javascript en Foros del Web. Hola amigo soy un poco nuevo en javascript pero aca va mi pregunta, yo tengo varias divs con id y yo quiero es obtener el ...
  #1 (permalink)  
Antiguo 07/09/2012, 20:29
 
Fecha de Ingreso: marzo-2011
Ubicación: Punta de Mata
Mensajes: 106
Antigüedad: 13 años, 1 mes
Puntos: 0
Obtener datos

Hola amigo soy un poco nuevo en javascript pero aca va mi pregunta, yo tengo varias divs con id y yo quiero es obtener el ultimo id ejemplo:

<div id="25" >hgmgmg</div>
<div id="24" > dnksjdn</div>
<div id="23" >jnmejj</div>


bueno eso varia por que hace una consulta a la base de datos para saber cualquier texto, yo lo que busco es que sivaria solo obtener el ultimo id en este caso "25" le agradezco bastante esa ayuda y otra mas:
  #2 (permalink)  
Antiguo 08/09/2012, 02:26
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Respuesta: Obtener datos

Hola:

Te recomiendo que uses otro formato para los atributos id, porque no son válidos los números. Deberían empezar por una letra y creo que también vale el guión bajo.

Si esos div's están en un contenedor con id="contenedor", puedes obtener la colección de divs y sabes que se trata del último.

divs = document.getElementById("contenedor").getElementsB yTagName("div");
busco_el_id = divs[divs.length - 1].id;

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #3 (permalink)  
Antiguo 15/09/2012, 14:05
 
Fecha de Ingreso: marzo-2011
Ubicación: Punta de Mata
Mensajes: 106
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: Obtener datos

hola amigo usted me puede ayudar con este codigo al parecer es para actualizar en tiempo real para red social vea pero no logro en tender muchos codigo si me ayuda le agradezco bastante:
Código Javascript:
Ver original
  1. var _d  = document;
  2. var _w  = window;
  3. var d       = document;
  4. var w       = window;
  5. var siteurl = "/";
  6.  
  7. var disable_animations  = false;
  8.  
  9. var window_loaded   = false;
  10. if( d.addEventListener ) {
  11.     d.addEventListener("load", window_onload, false);
  12.     w.addEventListener("load", window_onload, false);
  13. }
  14. else if( d.attachEvent ) {
  15.     d.attachEvent("onload", window_onload);
  16.     w.attachEvent("onload", window_onload);
  17. }
  18. function window_onload() {
  19.     if( window_loaded ) {
  20.         return;
  21.     }
  22.     window_loaded   = true;
  23.     setInterval(keep_session, 300000);
  24.     if(posts_synchronize) {
  25.         setTimeout(posts_synchronize, 3000);
  26.     }
  27.     if(dbrd_check_tabs) {
  28.         if( w.location.pathname && w.location.pathname.match("/dashboard") ) {
  29.             setTimeout(dbrd_check_tabs, 10000);
  30.         }
  31.     }
  32. }
  33.  
  34. function keep_session()
  35. {
  36.     var req = ajax_init();
  37.     if( ! req ) { return; }
  38.     req.onreadystatechange  = function() { };
  39.     req.open("POST", "http://skaiss.com/ajax/keepsession/r:"+Math.round(Math.random()*1000), true);
  40.     req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  41.     req.send(null);
  42. }
  43.  
  44. function ajax_init(is_xml)
  45. {
  46.     var req = false;
  47.     if (w.XMLHttpRequest) {
  48.         req = new XMLHttpRequest();
  49.         if (req.overrideMimeType) {
  50.             if( is_xml ) { req.overrideMimeType("application/xml"); }
  51.             else { req.overrideMimeType("text/plain"); }
  52.         }
  53.     } else if (w.ActiveXObject) {
  54.         try { req = new w.ActiveXObject("MSXML3.XMLHTTP"); } catch(exptn) {
  55.         try { req = new w.ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch(exptn) {
  56.         try { req = new w.ActiveXObject("Msxml2.XMLHTTP"); } catch(exptn) {
  57.         try { req = new w.ActiveXObject("Microsoft.XMLHTTP"); } catch(exptn) {
  58.         }}}}
  59.     }
  60.     return req;
  61. }
  62. function posts_synchronize()
  63. {
  64.     if( postcomments_open_state ) {
  65.         for(var i in postcomments_open_state) {
  66.             if( postcomments_open_state[i] != 0 ) {
  67.                 return false;
  68.             }
  69.         }
  70.     }
  71.     if( dropcontrols_last_open || postuserbox_last_open ) {
  72.         return false;
  73.     }
  74.     var req = ajax_init(false);
  75.     if( ! req ) { return; }
  76.     var dv  = d.getElementById("posts_html");
  77.     if( ! dv ) { return; } 
  78.     var url = w.location.href.toString();
  79.     if( ! url ) { return; }
  80.     if( url.substr(0, siteurl.length) == siteurl ) {
  81.         url = url.substr(siteurl.length);
  82.         url = "http://skaiss.com/from:ajax/r:"+Math.round(Math.random()*1000);
  83.     }
  84.     else {
  85.         url = url.replace(/^http(s)?\:\/\//, "");
  86.         url = url.substr(url.indexOf("/"));
  87.         url = "http://skaiss.com/from:ajax/r:"+Math.round(Math.random()*1000);
  88.     }
  89.     var i, ch, lastpostdate = "", lastpostdates = [];
  90.     for(i=0; i<dv.childNodes.length; i++) {
  91.         ch  = dv.childNodes[i];
  92.         if( !ch.id || !ch.id.match(/^post_/) || !ch.className.match(/^(m)?post/) || !ch.getAttribute("postdate") ) { continue; }
  93.         lastpostdates[lastpostdates.length] = parseInt(ch.getAttribute("postdate"), 10);
  94.     }
  95.     for(i=0; i<lastpostdates.length; i++) {
  96.         lastpostdate    = Math.max(lastpostdate, lastpostdates[i]);
  97.     }
  98.     req.onreadystatechange  = function() {
  99.         if( req.readyState != 4  ) { return; }
  100.         if( ! req.responseText ) { return; }
  101.         var txt = ltrim(req.responseText);
  102.         if( txt.substr(0,3) != "OK:" ) { return; }
  103.         txt = txt.substr(3);
  104.         dv.innerHTML    = txt;
  105.         setTimeout(posts_synchronize_step2, 1);
  106.         setTimeout( function() {
  107.             var i, all  = dv.getElementsByTagName("INPUT");
  108.             for(i=0; i<all.length; i++) {
  109.                 postform_forbid_hotkeys_conflicts(all[i]);
  110.             }
  111.             all = dv.getElementsByTagName("TEXTAREA");
  112.             for(i=0; i<all.length; i++) {
  113.                 postform_forbid_hotkeys_conflicts(all[i]);
  114.                 input_set_autocomplete_toarea(all[i]);
  115.             }
  116.         }, 1 );
  117.     }
  118.     req.open("POST", url, true);
  119.     req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  120.     req.send("lastpostdate="+encodeURIComponent(lastpostdate));
  121.     if(sync_tmout) {
  122.         clearTimeout(sync_tmout);
  123.         sync_tmout  = false;
  124.     }
  125.  
  126.     $(document).trigger("modifypost");
  127. }
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:06.