Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   не работает усдовие? (https://javascript.ru/forum/dom-window/61708-ne-rabotaet-usdovie.html)

Cdelphi78 04.03.2016 11:24

не работает усдовие?
 
Не могу понять в чем тутдело
<p class="icon_list_soc"><a class="product-statistic-soc__item" href="/product.php?pid=32"><i class="icon-p-ok active"></i></a><a class="product-statistic-soc__item" href="/product.php?pid=72"><i class="icon-p-ok active"></i></a></p>

$(function() {
			var href = $(".product-statistic-soc__item").attr('href');
			//alert(href);
				if ( 'href' === '/product.php?pid=32') {
					alert('Условие работает');
					$(this).css({ "display":"none"});
					
				}
			
		});

destus 04.03.2016 11:43

Cdelphi78,
а разве строка href равна строке /product.php?pid=32 ?

Cdelphi78 04.03.2016 12:05

destus,
Спасибо, неравна? сейчас проверю

Cdelphi78 04.03.2016 12:06

Вроде правильно написал, что вы имеете ввиду?

destus 04.03.2016 12:08

Цитата:

Сообщение от Cdelphi78 (Сообщение 409900)
Вроде правильно написал

А может нет? https://learn.javascript.ru/comparison

Cdelphi78 04.03.2016 12:17

Я смотрел эту статью не очень понятно по ней.
Вроде заработало, убрал апостолы прописал кавычки, однако теперь не работает this почему то?

destus 04.03.2016 12:24

Cdelphi78,
В данном случае $(this) ссылается на document, а его скрывать нельзя.
<script>
        $(function () {
            $(".product-statistic-soc__item").attr('href') === '/product.php?pid=32' && $(".product-statistic-soc__item").css({ "display": "none" });
        });
    </script>
    <p class="icon_list_soc"><a class="product-statistic-soc__item" href="/product.php?pid=32"><i class="icon-p-ok active"></i></a><a class="product-statistic-soc__item" href="/product.php?pid=72"><i class="icon-p-ok active"></i>123</a></p>

Cdelphi78 04.03.2016 12:33

щас условие не работает он не выбирает элемент с pid=32 и скрывает оба

destus 04.03.2016 12:38

Cdelphi78,
<script>
        $(function () {
            $(".product-statistic-soc__item").each(function () {
                $(this).attr('href') === '/product.php?pid=32' && $(this).css({ "display": "none" });
            })
        });
    </script>
    <p class="icon_list_soc"><a class="product-statistic-soc__item" href="/product.php?pid=32"><i class="icon-p-ok active"></i>222</a><a class="product-statistic-soc__item" href="/product.php?pid=72"><i class="icon-p-ok active"></i>123</a></p>

Cdelphi78 04.03.2016 12:43

Destus, заработало, большое спасибо, без вас бы не справился)


Часовой пояс GMT +3, время: 02:07.