A
Andy Dingley
What does ID do that CLASS doesn't?
JavaScript
What does ID do that CLASS doesn't?
The example below shows use of id. Upon submission, the script looks
for empty fields, and dynamically creates the CSS based on the name of
the field, in this case firstname. IMHO implementing this with class
would be a lot more difficult.
Seems like we are getting a lot of specialized rules here.dorayme said:Jeff, as you are a pretty regular poster here now, would you
consider not quoting the whole of a post to say things like
nicely done? No need to leave in the whole lot of code supplied
by Jonathan. I hope you are not offended by this being said.
Neredbojias said:I'd say "id" has a definite place
in the scheme of things.
Ed Mullen said:What do you mean by "current?" I don't get that.
Yeah, but I still don't get the benefit of using a non-re-usable
selector when the re-usable selector does the same thing. That's what
I'm asking about.
How is it lost? I can search for - id="foo" as easily as I can search
for - class="foo", right? What is "lost" in the composition or
rendering of a page?
I just don't get the functional difference. Nor the practical difference.
simple include menu php called "menu.php":
<?php
// Make a generic array for menu
$menu=array();
// And fill it with your sites page info
$menu[]=array('href' => '/', 'text' => 'Home');
$menu[]=array('href'=>'/law.php', 'text'=>'The Law');
$menu[]=array('href'=>'/diy.php', 'text'=>'How to DIY');
$menu[]=array('href'=>'/hire.php', 'text'=>'Hire Me');
$menu[]=array('href'=>'/links.php', 'text'=>'Links');
$menu[]=array('href'=>'/contact.php', 'text'=>'Contact');
//Get the index of the page we are on
$onIdx=pageIndex($menu);
// build the menu start UL
$buf='<ul class="menu">';
// iterate array to build menu
for($i=0, $ii=count($menu); $i<$ii; $i++){
$buf.='<li>'; // start LI
if($i==$onIdx){ //Non-link on this page
$buf.='<span>' . $menu[$i]['text'] . '</span>';
}
else { // build link
$buf.='<a href="' . $menu[$i]['href'] . '">';
$buf.=$menu[$i]['text'] . '</a>';
}
$buf.='</li>'; // close LI
}
$buf.='</ul>'; // close UL
echo $buf; // write menu
//function to determine what page you are on and return array index#
function pageIndex($menu){
$idx=0;
$here=parse_url($_SERVER['REQUEST_URI']);
for($i=0, $ii=count($menu); $i<$ii; $i++){
if($here['path']==$menu[$i]['href']){
$idx=$i;
break;
}
}
return $idx;
}
?>
BootNic said:<?php
#menu array
$menu = array('/index.php' => 'Home',
'/law.php' => 'The Law',
'/diy.php' => 'How to DIY',
'/hire.php' => 'Hire Me',
'/links.php' => 'Links',
'/contact.php' => 'Contact');
#current page
$location = $_SERVER["SCRIPT_NAME"];
BootNic said:<ul class="menu">
<?php
#menu array
$menu = array('/index.php' => 'Home',
'/law.php' => 'The Law',
Adrienne Boswell wrote:
There's no need for either. The elements all appear in the form fields
collection and you can iterate through the collection and set styles
with just the form field reference. With that reference you can also
find the label.
Usually when you mark fields, you have to unmark fields which the OP
has now "fixed". So you are iterating through collections regardless..
Jeff
Sure it does, but a lot of people use id without even considering
whether they actually need to or not.
The higher specificity of id over class selectors has caused me grief in
the past, so I don't use id at all any more unless I've got a real
reason to. If I do happen to need an id for something, I still usually
assign a class selector and use that in the stylesheet instead of id.
Jeff said:Seems like we are getting a lot of specialized rules here.
I don't see any complaints on unattributed snipping which often changes
the meaning of a post to seem like something the OP never intended.
Um.
In my case, I wanted to leave the code intact, these posts are
archived and they lose meaning without some context.
Usually when you mark fields, you have to unmark fields which the OP
has now "fixed". So you are iterating through collections regardless..
Jeff
Hi.
Following on from my last thread about coding, I find myself asking
what is the best way to do the 'current page' thing on a menu so I can
include it with PHP. Once I've learned about PHP. In my
early-stage-of-design site I am naming the page body with an 'id',
then changing the id of a menu item so that CSS changes the look of
it.
I think. (I'll go back and have a look in a minute).
www.thermachek.com/temp/
Anyway, if I go the PHP route what I'll need is a menu that can be cut
and pastedand included and *not* need tweaking (by changing the menu
item that is 'current') for each page. Can anyone point me to the URL
of a tutorial for such a menu system or give me the name of such so I
can look it up please?
Ta muchly in advance.
Jeff's script seems to be the dogs swallocks judging by the replies,
DOH! JONATHANS script.... sorry.
"dogs swallocks"?
BootNic said:<?php
#menu array
$menu = array('/index.php' => 'Home', '/law.php' => 'The Law',
'/diy.php' => 'How to DIY', '/hire.php' => 'Hire Me', '/links.php'
=> 'Links', '/contact.php' => 'Contact'); #current page
Yep, much simpler...
$location = $_SERVER["SCRIPT_NAME"];
And for OP and is simple case, yes this is simpler. Just sometimes
URL != $_SERVER["SCRIPT_NAME"]...I have some sites where they don't.
I read it as a euphemism for "the dog's bollocks".
Non-native speakers can sometimes find this phrase confusing. To call
something either a dog or bollocks is to say that it's held in generally
low esteem. But "the dog's bollocks" means the opposite: brilliant,
outstanding, the state of the art.
"dogs swallocks"?
If you sites is straight forward and the URL will always match the
script name (i.e., not created pages from a dB) then BootNic's version
is your ticket.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.