Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/08/2012, 12:44
Avatar de fullmental
fullmental
 
Fecha de Ingreso: octubre-2004
Ubicación: México DF, Xochimilco
Mensajes: 593
Antigüedad: 19 años, 6 meses
Puntos: 3
existe una una manera mas elegante?

Hola

Tengo un código que funciona, sin embargo siento que puede ser mejorado, es decir, hacer lo mismo con menos código.


Código HTML:
$(document).ready(function() {
$('a[href*=#]').click(function(){
	

	var sectionHash = $(this).attr('href');
	
	var firstCharacter = sectionHash.substring(1,2);
	var hashTail = sectionHash.substring(2);
	var forceToCamel = firstCharacter.toUpperCase();
	var sectionName = sectionHash.replace('#', 'box')
	var target = "box"+forceToCamel+hashTail;
	
	
	$("#inputBox").html(target);
	
	
});
Se puede acortar éste código? le última línea obvio sólo es para probar la funcionalidad.

Lo que hace es tomar el href="#seccion" a algo como boxSeccion... para después utilizarlo con jquery y hacer algunos efectos especiales ;)