Jump to content
SandySynaptik

My First Mistake In Jquery

Recommended Posts

Here is source:<!DOCTYPE HTML><html lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>JQuery for Dummies</title><style type="text/css">.centerimage { width: 300px; height: 300px; position: absolute; left: 50%; top: 50%; margin-left: -150px; margin-top: -150px;}</style> </head><body><img src="media/images/image.jpg" height="28" width="28" alt="This is an image" /></body><script type="text/javascript" href="media/js/jquery-1.5.2.min.js" > </script><script type=”text/javascript”>$(document).ready(function(){ alert(jQuery('img').attr('alt')); });</script></html> All the js, css,and images are loading correctly. Why can't I see any prompt box? Another question, if I add class="centerimage" inside the img then browser neglects the height and width

Share this post


Link to post
Share on other sites

Don't put the <script> element outside the body. It probably is best even to put it inside the <head>. Having anything outside the head or body sections is incorrect HTML. You might want to relearn HTML before continuing with Javascript. Try removing the height and width attributes from the image, or remove the height and width rules from the CSS, whichever one you're having problems with. I know the CSS precedence rules, but I don't know how it works with HTML attributes.

Share this post


Link to post
Share on other sites

@Duotone FoxI have moved both javascripts to head and also removed height and width rules form css file. The page still is as it was, there should be a alert box according to the book. P.S.- Don't be so rude..

Share this post


Link to post
Share on other sites

Have you checked the error console to see if something isn't working properly? In Firefox you can view it by pressing Control+Shift+J

Share this post


Link to post
Share on other sites

<script type="text/javascript" href="media/js/jquery-1.5.2.min.js" > </script> should be <script type="text/javascript" src="media/js/jquery-1.5.2.min.js" > </script> It seems the quotes used in your code are not proper quotes so the link to jquery, and <script type=”text/javascript”> are not registering as a javascript script tag, (unless it the forum that has rewritten them) select the the quote characters of your code and type the correct shift+2, if you look they seem italic when they should be below <script type="text/javascript">

Share this post


Link to post
Share on other sites

@IngolmeThere is no message, error or warning in the error console.@dsonesukWhat are you talking about Shift+2, I have a standard keyboard and there is @ if I press Shift+2 and the files are loading correctly (I can go to that file if I click on its path in view-source mode)

Edited by Sandy Synaptik

Share this post


Link to post
Share on other sites

Could you provide a working example for us to see?

Share this post


Link to post
Share on other sites

OK! the code you provided when i pasted in my page the javascript was treated as text because the quotes are " instead of " , on my keyboard shift + 2 produces ", obviously if yours produces @ instead, I would have thought you would have used your brain and guessed that I use a different keyboard layout to you, as not everyone has the same keyboard layout and use the correct keyboard key combination to produce ". The href should not be used when sourcing a javascript file, IT SHOULD BE src. Right the other problem is <script type=”text/javascript”>$(document).ready(function(){alert(jQuery('img').attr('alt'));}); Which is it! you should have an error appear stating that jQuery is not defined, in its default state jquery will use $ to identify as jquery code, to use jQuery you would have to inform it will use this instead with jQuery.noConflict();

Share this post


Link to post
Share on other sites

Unfortunately, I don't seem to be able to load your page at the moment. The connection keeps timing out for some reason. However, the Javascript won't run because of an error the validator is showing me.

Share this post


Link to post
Share on other sites

Huh, finally it is ok, validated the page and its done. Validation helps!At last, isn't there any offline html validator? Thanks all for helping an idiot like me, and sorry if your brain's temperature raised in helping me.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...