Как получить текст прежде данный элемент с помощью jQuery?

Просто заметка на полях относительно "потребности Mac" точка. Я только что купил один для несвязанной технической разработки и попытался выбрать iPhone SDK из любопытства. Никакая удача: все, что я имею, является Tiger (OS X 10.4) на Mac PPC, в то время как Apple заявляет, что мне нужно 10.5.5 на Intel для в настоящее время dowloadable версии.

14
задан czuk 9 October 2009 в 13:09
поделиться

3 ответа

How about collecting them into an array instead of two calls to $:

var texts = $('span, b').map(function(){
    return this.previousSibling.nodeValue
});
texts[0]; // "Some text followed by "
texts[1]; // " and another text followed by "

References:

24
ответ дан 1 December 2019 в 09:13
поделиться

I have come up with a following solution:

var c = $("span").context.previousSibling;
alert(c.data);

But I am not sure how safe it is when using different browsers?

0
ответ дан 1 December 2019 в 09:13
поделиться

I'm afraid you will need to use regular expressions for that. In order to get the text before span element use something like this:

var txt = $('span').parent().html();
var regex = /(.*)<span>/;
txt = txt.match(regex)[1];

Modify the regex to match other parts of the string as well.

3
ответ дан 1 December 2019 в 09:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: