T
T
ton1_rose2017-03-13 18:34:44
css
ton1_rose, 2017-03-13 18:34:44

How to change styles for an element only on a page with a specific URL?

Good afternoon %username%
The question has matured, how can I change the styles of an element only on a page with a specific URL
I thought at first, try to refer to the parent selector and get by with pure CSS , using adjacent and child selectors + > but unfortunately this option cannot be implemented (
In Due to the lack of skill in writing scripts in JS (jQuery), I wanted to turn to you dear friends.
Please help me write a simple script with one of these options and the following logic:

если url страницы http://sitename/pages/page1/
1 вариант:  тогда к элементу с классом "obj" добавить стиль color: red; 
2 вариант:  тогда к элементу с классом "obj" добавить класс "obj2"

I would really appreciate it if you could help me figure it out :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nwton, 2017-03-13
@ton1_rose

https://jsfiddle.net/fhjv0bcu/1/
Add the special class to the id=item object depending on the url.
ps You can't do web if you don't master js. (not jquery, but js)

A
Alexander Pushkarev, 2017-03-13
@AXP-dev

c jquery
1)

if ( location.pathname == '/pages/page1/' ) {
   $('.obj').css('color', 'red');
}

2)
if ( location.pathname == '/pages/page1/' ) {
   $('.obj').addClass('obj2');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question