1

Help on this guys,

I have here a script that adds an ID on body tag

this is the result I see

<body id="xxx-cat">

with the script I'm using below

<script>
$(document).ready(function(){
// Edit xxx-cat to match desired category link id:
$('body').attr("id","xxx-cat");
if ($('body[id]')) {
var bid = $("body").attr("id");
// Keep the next command on one line
$('div.droplinebar li a[class='+bid+']').addClass('current');
}
})
</script>

How can I make the ID's (1,2,3,4), because I have 4 pages and want it like

<body id="1"> for the home page
<body id="2"> for the about
<body id="3"> for the clients
<body id="4"> for the contact

and by the way this is a tumblr custom page, can't use PHP here

Francis Alvin Tan
  • 915
  • 1
  • 14
  • 35
  • Are these 4 body tags in same html? – haitaka Feb 21 '13 at 02:52
  • there should be only one body in a page, why bother giving them different id's? – andri Feb 21 '13 at 02:53
  • Note that HTML IDs must start with a letter (see [What are valid values for the id attribute in HTML?](http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html)). – Cymen Feb 21 '13 at 02:54
  • its because Im assigning different background to it – Francis Alvin Tan Feb 21 '13 at 03:01
  • @Cymen That's not true according to the HTML5 spec and is not enforced by browsers even with HTML4 – Dennis Feb 21 '13 at 03:04
  • @Dennis Good point on HTML5 (couldn't find the correct page at w3.org with a quick search) but just because it's not enforced doesn't meant it isn't a good idea to follow the standard. If someone is asking a question like this, I'm going to assume they are using HTML4. – Cymen Feb 21 '13 at 03:06

2 Answers2

1

As I understand your question, you can change the scripting, but not the page itself (because it is on Tumblr?)

Try something like:

$(document).ready(function(){
    var bodyId = '1'; // Set to 1, 2, 3, 4 etc    
    $("body").attr('id', bodyId);
    $('div.droplinebar li a.'+bodyId).addClass('current');
});

However as mentioned in the comments, you shouldn't just use an number for your ID, consider revising this if possible.

Alex Osborn
  • 9,674
  • 3
  • 30
  • 44
1

found an answer to My question

$(function() {
    var pathname = window.location.pathname;
    var getLast = pathname.match(/.*\/(.*)$/)[1];
    var truePath = getLast.replace(".php","");
    if(truePath === '') {
        $('body').attr('id', 'home');
    }
    else {
        $('body').attr('id', truePath);
    }
});

results

home = <body id="home">
about = <body id="about">
clients = <body id="clients">
contacts = <body id="contacts">
Francis Alvin Tan
  • 915
  • 1
  • 14
  • 35