Jaaaaabbb
Jaaaaabbb

Reputation: 121

xpath functions not supported in jquery

I have the following xpath that I need to run, but Jquery doesn't support the functions....so how can i actually make this work in jquery ?

$("//*[br]/text()[string-length(normalize-space()) != 0]").each( ....

Upvotes: 0

Views: 1034

Answers (3)

meder omuraliev
meder omuraliev

Reputation: 186562

Um - modern jQuery doesn't support XPath. jQuery isn't an Xpath parsing utility.

However, I would recommend you actually translate that into jQuery... perhaps something like

$('*[br]').filter(function() {
    var text = $(this).text(), normalized = $.trim( text );
    return normalized.length>0
});

Though you may need an additional regex replacement of multiple whitespace, I'm not quite sure how that xsl/xpath function works.

Upvotes: 1

bastianneu
bastianneu

Reputation: 2069

Please check the new compatibility Plugin for JQuery:

http://docs.jquery.com/Release:jQuery_1.2#XPath_Compatibility_Plugin

But keep one thing in mind: "XPath is a language to traverse nodes in XML document during the transformation (look for XSLT)." :-)

Upvotes: 0

Kieran Hall
Kieran Hall

Reputation: 2627

John Resig (the author of jQuery) wrote an Xpath Plugin.

Upvotes: 0

Related Questions