Jump to content

Recommended Posts

Posted

In a practical example listed below, I only see the last line, not the series of text that I would expect given that I have tried a series of options. Which would you expect to work, or please suggest what I am doing incorrectly.

 

$(document).ready(function(){

var pTop = $("#content").position().top;

var pLeft = $("#content").position().left;

var h = $("#content").height();

var w = $("#content").width();

 

$("#message").text( "\n Top: " + pTop + ", left: " + pLeft);

$("#message").text( "

");

$("#message").text( "\\n \n \\\n ");

$("#message").text( "width: " + w + " height: " + h);

...

Thanks for any help.

Posted

Well, in each line, you are resetting the #message's text value, you aren't adding to it. You probably should be using "append" instead of "text", which should insert your specified code at the end of the div.

 

And, as a sidenote, since you are dealing with HTML code here, you probably should be using
s for line breaks instead of \n.

 

http://docs.jquery.com/Manipulation/append#content

 

$(document).ready(function(){
               var pTop = $("#content").position().top;
               var pLeft = $("#content").position().left;
               var h = $("#content").height();
               var w = $("#content").width();

               $("#message").append( "\n Top: " + pTop + ", left: " + pLeft);
               $("#message").append( "
");
               $("#message").append( "\\n  \n \\\n ");
               $("#message").append( "width: " + w +  "  height: "  + h);

Posted (edited)

Easiest way is to get Firebug for Firefox, or if you already have GOogle Chrome or Internet Explorer 8 they come with Javascript consoles too. Then you don't even need to put line breaks and stuff.

 

And then you can start using: console.log(messageVariable)

 

$(document).ready(function(){
               var pTop = $("#content").position().top;
               var pLeft = $("#content").position().left;
               var h = $("#content").height();
               var w = $("#content").width();

              console.log("Top: " + pTop + ", left: " + pLeft);
              console.log("width: " + w +  "  height: "  + h);

 

Make sure to remove the console.log lines before going live though, they will throw an error message: "Console is not defined" when viewed with browsers without a javascript console.

Edited by BeeDev
Posted

You can hit F12 to open Developer Tools or go to "Tools" -> "Developer Tools F12" from the top right hand menu.

 

Then choose the "Script" tab on the box that pops up from the bottom of your browser (You may need to enlarge the box as it may come up minimized at first). Then on the right hand portion you see more tabs, but by default "Console" will be chosen.

Posted

BeeDev:

I tried using your suggestion:

console.log("Top: " + pTop + ", left: " + pLeft);

console.log("width: " + w + " height: " + h);

 

I don't see any output in the console for either IE8 or FireFox. Could you suggest something that I might be doing incorrectly?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...