Generate jQuery HTML Element with Expected Length of 1, element.length Returns 15
The function I was trying to use wasn't working, so I tested the le开发者_如何学JAVAngth selection (should be one):
$('header').append('<p id="ancho_ventana"></p>');
$(document).ready(function(){
alert(('p#ancho_ventana').length); //outputs "15"
});
Also tried with
var ancho = $('<p id="ancho_ventana"></p>').hide();
$(document).ready(function(){
$(window).bind('resize',function(){
alert(('p#ancho_ventana').length);
})
});
And the second function outputs the same. Why is this happening?
Your alert
returns the length of the string p#ancho_ventana
, which contains 15 characters.
I think you meant:
alert($('p#ancho_ventana').length);
精彩评论