Rabbit.Selector.value()

The value() method is used to get text value of the specified node found by the CSS selector on the current page.

Syntax

Rabbit.Selector.value(selector, parent)

Parameters

Parameter Type Description
selector String CSS selector.
parent Node object Context node against which the specified CSS selector will be executed.

Return Value

Type Description
String Text value of the node or nodes found by the css selector.

注釈

If the specified CSS selector returns multiple nodes, the function returns concatenated string consisting of all text values of all nodes that were found.

Example 1

The example below demonstrates how to get the value of the TITLE element available on the page.

Source HTML code available on your original desktop site page:

<html>
 <head>
   <title>Document Title</title>
 </head>
</html>

You need to add the following code to your template to display page title on your mobile website:

<!--{= Rabbit.Selector.value('title') }-->

The result will look like:

Document Title

Example 2

The example below demonstrates how to get values of all list items (LI elements) available on the page.

Source HTML code available on your original desktop site page:

<html>
 <body>
   <ul>
     <li>List Item 1</li>
     <li>List Item 2</li>
   </ul>
 </body>
</html>

You need to add the following code to your template to display values of all list items available on the page:

<!--{= Rabbit.Selector.value('li') }-->

The result will look like:

List Item 1List Item 2

Example 3

The example below demonstrates how to get node value from the specified context node using CSS selector.

Source HTML code available on your original desktop site page:

<html>
 <body>
   <ul id="list1">
     <li>List 1 Item 1</li>
     <li>List 1 Item 2</li>
   </ul>
   <ul id="list2">
     <li>List 2 Item 1</li>
     <li>List 2 Item 2</li>
   </ul>
 </body>
</html>

You need to add the following code to your template to get node value from the specified context node using CSS selector:

<!--{= Rabbit.Selector.value('li:first-child', document.getElementById('list2')) }-->

The result will look like:

List 2 Item 1