SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hello I have a SharePoint 2007 MOSS publishing site that uses a custom master page for most of its pages. I'd like to be able to apply some jQuery to one of those pages only but there's no way to uniquely identify the element for that page only with a CSS selector.

Is it possible to do something like this in my master page so that jQuery can know what page is currently being rendered and, if so, how?

<body id="<% some_identifier_here %>">


share|improve this question

My guess is that there is a way to uniquely identify the element with a selector and you just haven't found it yet. Also, have you considered adding the jQuery to the specific page layout rather than the master page? That'll narrow the scope for you.

share|improve this answer
Thanks for your answer. The same page layout is also used across pages so there's no way of narrowing the scope that way. If there is a way of identifying the element I'm yet to find it. – user878 Jul 6 '10 at 12:02
Try using Firebug or the IE Dev Toolbar. A selector should be discoverable. – Mike Oryszak Jul 6 '10 at 14:33

Thanks for both of your answers. I solved this in the end by adding a new field to my master page's content type called Identifier and embedding its value into my page's wrapper div like this.

<div id="wrapper" class="<SharePoint:FieldValue FieldName='Identifier' runat='server'/>">

which gives me

<div id="wrapper" class="homePage" runat='server'/>">

on my home page and means I can identify it in my CSS and jQuery code.

share|improve this answer

Not 100% sure what you are trying to do, but can't you add some JavaScript (or server side) code that checks the location object and based on the name / location of the page take a certain action?

Or use JQuery to try and access the element. If it returns null then you are not on the right page?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.