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 %>">


3 Answers 3


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.

  • 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, 2010 at 12:02
  • Try using Firebug or the IE Dev Toolbar. A selector should be discoverable. Jul 6, 2010 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.


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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.