george Posted April 16, 2011 Share Posted April 16, 2011 This works as intended in IE, but not in FF <script type="text/javascript"> $(document).ready(function(){ /* give all divs with an id attribute a clear border */ $("div[id]").css("border","1px, solid black"); }) </script> How come? And is there a discrepencies list anywhere? Link to comment Share on other sites More sharing options...
thescientist Posted April 16, 2011 Share Posted April 16, 2011 This works as intended in IE, but not in FF <script type="text/javascript"> $(document).ready(function(){ /* give all divs with an id attribute a clear border */ $("div[id]").css("border","1px, solid black"); }) </script> How come? And is there a discrepencies list anywhere? this is what I would try <script type="text/javascript"> $(document).ready(function(){ /* give all divs with an id attribute a clear border */ $("div").each(function(){ if(this.id){ this.css("border","1px solid black"); }; }); });</script> http://api.jquery.com/each/ Link to comment Share on other sites More sharing options...
george Posted April 16, 2011 Author Share Posted April 16, 2011 No. The intended outcome did not occurr in either browser. I'll just switch back to the one that worked in IE, since this is just an excersize to correct the css I have for a site. But the bigger question looms, why does this work in IE and not FF? I thought jQuery was supposed to be cross browser. It is also supposed to be assessable, but not by sans-mouse navagation it is not. Link to comment Share on other sites More sharing options...
thescientist Posted April 16, 2011 Share Posted April 16, 2011 it appears I meant to say border, not border style. Are there any errors on the page at all when you view it?can you post the relevant HTML, or post a link, so we can try it with the same code you are? Link to comment Share on other sites More sharing options...
dsonesuk Posted April 16, 2011 Share Posted April 16, 2011 try this $(document).ready(function(){ /* give all divs with an id attribute a clear border */ $("div").each(function(){ if($(this).attr("id")){ $(this).css("border","1px solid black"); }; }); }); Link to comment Share on other sites More sharing options...
thescientist Posted April 16, 2011 Share Posted April 16, 2011 damn. good call on the .attr. that's probably it. Link to comment Share on other sites More sharing options...
george Posted April 16, 2011 Author Share Posted April 16, 2011 That did it. Thanks. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 16, 2011 Share Posted April 16, 2011 damn. good call on the .attr. that's probably it.your code would have worked, if it was not using the js method instead of jq, to change styling (and border-style error, of course) $(document).ready(function(){ /* give all divs with an id attribute a clear border */ $("div").each(function(){ if(this.id){ $(this).css("border","1px solid black"); }; }); }); Link to comment Share on other sites More sharing options...
george Posted April 16, 2011 Author Share Posted April 16, 2011 What would be really cool is if I could disply the div id name when I hover over the div. Link to comment Share on other sites More sharing options...
dsonesuk Posted April 16, 2011 Share Posted April 16, 2011 thats easy, get id attribute name and assign it to title attribute of div $(document).ready(function(){ /* give all divs with an id attribute a clear border */ $("div").each(function(){ if($(this).attr("id")){ $(this).css("border","1px solid black"); var idname = $(this).attr("id") $(this).attr("title", idname) }; }); }); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.