jquery - trying to get an element's position, but it's always 'undefined' -


i'm trying # use in scrolltop function, 'undefined' have gone wrong?

<html><head><meta http-equiv=content-type content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css"> <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> <script src="http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js"></script> </head><body>  <div data-role="page" id="page5"  data-theme="c"> <br><br><br><br> <p><span id="1.11.13">1.11.13</span> lots of text here... </p>  <script> $(window).on('pageinit', function() {     console.log($('#1.11.13').css('top')); //undefined     console.log($('#1.11.13').position()); // undefined     //console.log($('#1.11.13').offset().top); = uncaught typeerror: cannot read property 'top' of undefined  });  </script></div></body></html> 

to use of meta-characters ( such !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) literal part of name, must escaped with 2 backslashes: \. example, element id="foo.bar", can use selector $("#foo\.bar").

so either escape special character:

$('#1\\.11\\.13') 

or use:

var id="1.11.13"; $("[id='"+id+"']") 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -