开发者

Generate jQuery HTML Element with Expected Length of 1, element.length Returns 15

开发者 https://www.devze.com 2023-04-06 08:24 出处:网络
The function I was trying to use wasn\'t working, so I tested the le开发者_如何学JAVAngth selection (should be one):

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号