Karmacoma
Karmacoma

Reputation: 668

Div class only in one page via jQuery

I've got a class:

.sample {
    background:url("../sample.png") repeat-x scroll 0 0 transparent;
    height:200px;
    position:absolute;
    top:0;
    width:100%!important;
    z-index:101
}

This is a mask and I want to use this class to be called in one page and not all the pages. How can i do?

Upvotes: 0

Views: 140

Answers (3)

Er. Anurag Jain
Er. Anurag Jain

Reputation: 1793

Add a title attribute to div in which you want to add class like title = "class_apply". and in other pages div add title like title = "no_class"

Now you have two options with jquery .

1.Add class in all pages div with id and title. and check for title attribute if title is no_class then remove class from those div.

var title = $('#divid').attr("title");
if(title == "no_class"){
  $('#divid').removeClass("divClass");
}

Or

2.make div in all pages with id and title. and check for title attribute if title is class_apply then add class to that div.

var title = $('#divid').attr("title");
if(title == "class_apply"){
  $('#divid').addClass("divClass");
}

Upvotes: 1

Vimalnath
Vimalnath

Reputation: 6463

Add the css file using:

drupal_add_css ('myfile.css');

myfile.css:

.sample {
    background:url("../sample.png") repeat-x scroll 0 0 transparent;
    height:200px;
    position:absolute;
    top:0;
    width:100%!important;
    z-index:101
}

or

use inline css stlye to suit your purpose.

Upvotes: 1

user1249679
user1249679

Reputation:

<? if (eregi("yourpagename", $_SERVER[REQUEST_URI])){?>
<script>
$('#divid').addClass("sample");
</script>
<?}?>

Upvotes: 0

Related Questions