Ver Mensaje Individual
  #4 (permalink)  
Antiguo 04/05/2014, 13:38
Avatar de Biiiiilm
Biiiiilm
 
Fecha de Ingreso: septiembre-2012
Mensajes: 27
Antigüedad: 11 años, 7 meses
Puntos: 1
Respuesta: Usar before() de JQuery

Pongo lo que me dices y no funciona...
Código:
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $(":radio:first-child").before("Texto anterior a botón ->");
  });
});
</script>
</head>
<body>

<button>Cliquéame</button>
<br /><input name="primero" type="radio" value="1" />1. Primero
<br /><input name="segundo" type="radio" value="2" />2. Segundo

</body>
</html>
Lo correcto es $('input[type="radio"]:first').before("Texto anterior a botón ->");

Por cierto, ¿cómo haríais para que fuese delante del segundo? En lugar del primero. Entiendo que podría usarse "last", pero... ¿Hay alguna manera de usar "second"? xD O similar...

Me vuelvo a contestar. Se usa :eq(0) ó :eq(1) para seleccionar el primero o el segundo, respectivamente ;)

Muchísimas gracias, Alexis88

Última edición por Biiiiilm; 04/05/2014 a las 13:49