php - Including file with jQuery and getting it's content length -
is possible things jquery:
i have empty html file index.php (with no content, important tags), have file content.php in inside there web-page content, example this: blablabla, lot of tags, divs , other content. example, content 700px long.
now thing jquery this: in file index.php between tags input command , after add 1 more jquery thing puts .content.heigth() variable (so show, how long content in file content.php (in example 700px)).
i have tried these things , goes fine until place have put variable file's content length.
here code. fix it, in opinion wrong.
all jquery commands written in index.php file.
$(document).ready(function() { $('body').append("<?php include ('content.php'); ?>"); $length = $('.content').length; });
$length shows me 0 should more 0 ^_^
the important thing know how long length of content in content.php file index.php file jquery or other language's help. file including possible .load('content.php') command, command doesn't see included file's content length.
thanks help! :)
$('body').append("<?php include ('content.php'); ?>");
don't that! there no reason it, , you'll hit problem line breaks and/or unescaped quotes. add <?php include ('content.php'); ?>
directly @ end of body, grab height document.ready (you there):
$(document).ready(function() { var height = $('.content').height(); alert(height) // or });
you mentioned .load('content.php')
in question. if direct php include suggested doesn't suit needs, this:
$(document).ready(function() { // want more specific container instead of body $(body).load('content.php', function(){ // can read height inside callback var height = $('.content').height(); alert(height) // or // continue program flow here // (for example, call function) }); // caution: here content didn't load yet. // if need refer it, callback above. });
and finally: if 0
$('.content').length
, that's because there no element class "content" in dom @ moment you're calling that. length
property of jquery object tells how many elements match selector used, 0 none.
Comments
Post a Comment