SandySynaptik Posted September 23, 2011 Share Posted September 23, 2011 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 Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2011 Share Posted September 23, 2011 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. Link to comment Share on other sites More sharing options...
SandySynaptik Posted September 23, 2011 Author Share Posted September 23, 2011 @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.. Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2011 Share Posted September 23, 2011 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 Link to comment Share on other sites More sharing options...
dsonesuk Posted September 23, 2011 Share Posted September 23, 2011 <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"> Link to comment Share on other sites More sharing options...
Drycodez Posted September 23, 2011 Share Posted September 23, 2011 Deleted! Link to comment Share on other sites More sharing options...
SandySynaptik Posted September 23, 2011 Author Share Posted September 23, 2011 @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) Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2011 Share Posted September 23, 2011 Could you provide a working example for us to see? Link to comment Share on other sites More sharing options...
SandySynaptik Posted September 23, 2011 Author Share Posted September 23, 2011 Here is an example:http://sandysynaptik.webs.com/example/jq.html Link to comment Share on other sites More sharing options...
dsonesuk Posted September 23, 2011 Share Posted September 23, 2011 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(); Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2011 Share Posted September 23, 2011 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. Link to comment Share on other sites More sharing options...
dsonesuk Posted September 23, 2011 Share Posted September 23, 2011 looking at you code it displays <script type=â€text/javascriptâ€> that is the problem. Link to comment Share on other sites More sharing options...
SandySynaptik Posted September 23, 2011 Author Share Posted September 23, 2011 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. Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2011 Share Posted September 23, 2011 You can download a program called Total Validator Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.