Foros del Web » Programando para Internet » Jquery »

Seleccionar los title de los img

Estas en el tema de Seleccionar los title de los img en el foro de Jquery en Foros del Web. Hola, apenas tengo experiencia en JQuery pero necesito coger los title de las imágenes y aplicar una funcion que me he bajado. Lo tengo así: ...
  #1 (permalink)  
Antiguo 03/01/2013, 06:50
 
Fecha de Ingreso: enero-2011
Mensajes: 84
Antigüedad: 13 años, 3 meses
Puntos: 4
Seleccionar los title de los img

Hola, apenas tengo experiencia en JQuery pero necesito coger los title de las imágenes y aplicar una funcion que me he bajado. Lo tengo así:

Código:
	<script>
	  $(function(){
	 
		$('img[title]').mbTooltip({ // also $([domElement]).mbTooltip  >>  in this case only children element are involved 
		  opacity : .97,       //opacity
		  wait:1,           //before show
		  cssClass:"default",  // default = default
		  timePerWord:70,      //time to show in milliseconds per word
		  hasArrow:false,			// if you whant a little arrow on the corner
		  hasShadow:true,
		  imgPath:"images/",
		  ancor:"mouse", //"parent"  you can ancor the tooltip to the mouse position or at the bottom of the element
		  shadowColor:"black", //the color of the shadow
		  mb_fade:200 //the time to fade-in
		});
	  });
	</script>
Pensaba que se hacía con el $('img[title]').mbTooltip pero me coge los title de los enlaces también y solo quiero el de las imágenes, como se escribe el selector?

Un saludo y gracias de antemano
  #2 (permalink)  
Antiguo 03/01/2013, 08:23
Avatar de emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Seleccionar los title de los img

El selector está correcto, te dejo otra variante también

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html lang="es-ar">
  3. <meta charset="utf-8" />
  4. <title>Html5</title>
  5. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  6.  
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. $(document).ready(function(){
  10. $("img[title]").css('border','solid 5px red')
  11.  
  12. // otra variante
  13. if($("a").is("[title]")){
  14. $("a").css('border','solid 5px #000');
  15. }
  16.  
  17. });
  18. //]]>
  19. </head>
  20. <p title="Hola en párrafo">Hola</p>
  21. <div>
  22. <img alt="" title="hola en Imágen" src="http://foros.emprear.com/img_fdw/reg.jpg" /><br />
  23. <img alt="" src="http://foros.emprear.com/img_fdw/reg.jpg" />
  24. </div>
  25. <p><a href="http://forosdelweb.com" title="FDW">FDW</a></p>
  26. </body>
  27. </html>

Asegurate de usar documentReady, si no funciona habría que revisar como estás usando ese plugin del tooltip, que no lo conozco

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.
  #3 (permalink)  
Antiguo 03/01/2013, 09:01
 
Fecha de Ingreso: enero-2011
Mensajes: 84
Antigüedad: 13 años, 3 meses
Puntos: 4
Respuesta: Seleccionar los title de los img

Gracias,

Al final lo he solucionado cambiando una línea del Script externo mbTooltip.js:

Código:
 if (this.options.live)$("[title]").live
("mouseover",function(){$(this).mbTooltip(options);});
por

Código:
 if (this.options.live)$("img[title]").live
("mouseover",function(){$(this).mbTooltip(options);});

Saludos

Etiquetas: javascript
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 18:54.