[JQuery] - выборка строки html без тега
Добрый день. Подскажите пожалуйста.
Есть код:
<label>
<?php if ($quote['code'] == $code || !$code) { ?>
<?php $code = $quote['code']; ?>
<input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" checked="checked" />
<?php } else { ?>
<input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" />
<?php } ?>
<?php echo $quote['title']; ?> - <?php echo $quote['text']; ?>
</label>
Вопрос. Как установить новое содержимое в последней строке, если там нет тегов? (<?php echo $quote['title']; ?> - <?php echo $quote['text']; ?>) Если бы были теги:
<label for="<?php echo $quote['code']; ?>"> // тут или mileage.city или mileage.oblast в зависимости от логики контроллера.
<?php if ($quote['code'] == $code || !$code) { ?>
<?php $code = $quote['code']; ?>
<input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" checked="checked" />
<?php } else { ?>
<input type="radio" name="shipping_method" value="<?php echo $quote['code']; ?>" />
<?php } ?>
<span class="title"><?php echo $quote['title']; ?></span> - <span class="text"><?php echo $quote['text']; ?></span></label>
</label>
то все выбирается хорошо так.
$('label[for="mileage.city"]').find('span[class="title"]').html(data.title);
$('label[for="mileage.city"]').find('span[class="text"]').html(data.text);
$('label[for="mileage.oblast"]').find('span[class="title"]').html(data.title);
$('label[for="mileage.oblast"]').find('span[class="text"]').html(data.text);
Как то же самое сделать, если теги не определенны в коде? Пробовал через after
$('input[value="mileage.city"]').after(data.text);
$('input[value="mileage.city"]').after(data.title);
но это вставляет еще одну строку , но не заменяет. |
Угу. Вот код HTML
<label> <input type="radio" value="mileage.city" name="shipping_method"> Доставка в пределах города, Расстояние доставки 0,00 км. - $0.00 </label> Как добраться до (Доставка в пределах города, Расстояние доставки 0,00 км. - $0.00), если нет тега ? |
pomansur,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(function(){
alert($.trim($("label")[0].lastChild.data));
})
</script>
</head>
<body>
<label>
<input type="radio" value="mileage.city" name="shipping_method">
Доставка в пределах города, Расстояние доставки 0,00 км. - $0.00
</label>
</body>
</html>
|
pomansur,
<label>
<input type="radio" value="mileage.city" name="shipping_method">
Доставка в пределах города, Расстояние доставки 0,00 км. - $0.00
</label>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
alert($('label').text());
</script>
|
Спасибо. Буду пробовать
|
| Часовой пояс GMT +3, время: 16:05. |