How to apply a css class to master page based on the url using jquery? [closed]


Tags: c#,jquery,asp.net,css,jquery-ui

Problem :

I need to apply one css class based on the page i am in..All the divisions are in master page..

Can anyone help me with the code on how to find the url of the page and apply the class to that page using jquery?

Suppose this is my url how do i get just default.asp from it?

http://www.w3schools.com/jquery/default.asp

Thanks.



Solution :

You can find the page name and then if it is specific page as per your requirement then you can add required css class on the fly:

 $(document).ready(function(){

      if (document.location.href.match(/[^\/]+$/)[0] == 'index.aspx')
      {
          //Add CSS in page header
          $("head").append("<script> .my-css-class{ /* put style here */} <script/>");
      }    
    });

    CSS Howto..

    LESS: how to use dumpLineNumbers

    How to change
  • to variable width on css dropdown submenu
  • How to give different content to every td in the table

    How to fix background Opacity css

    how to position these CSS elements without defining height and width

    Linking CSS button to email - How can it be done?

    How to prevent opening a link of the submenu when tapping the menu?

    How to make no borders in a td rowspan rows

    How can I turn a bullet image into a link?

    How do I properly add a scrollbar to a jQuery Mobile popup using iScrollview?

    How to add another text decoration definition with Javascript?

    How to use this CSS rule for divs? [JSFiddle]

    How do I make
  • with block elements sit beside each other?
  • How do I fit a fieldset to the size of its content with CSS?

    Disappearing div using JQuery - how do I stop it from reloading next time a page is opened

    How to toggle fade a DIV when hovered over an image

    how to select a input using jquery

    How to override inline css from external class?

    How do i use a simple string variable with jquery?

    how to display an image on small screens and videos on large screen in html

    How can I use CSS to set as my
  • background if I'm using the Zend framework?
  • How to make a rectangle mask with css

    how to make the background the same as the div size in css

    Superfish: How to keep sub menu open after it has been clicked

    How to reffer in CSS to an input which has class attached to?

    How to style jQuery UI's autocomplete list for mouse leave event?

    how to get this table to work properly?

    How to write regex to extract specific key format and value from CSS file?

    Jquery show/hide more data

    How to minify css files with RequireJS