Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.
Selection.data([key])
Return the value at the named data store for the first element in the set of matched elements. Mimics jquery.data
Parameter | Type | Description |
---|---|---|
key (optional) | string | A string naming the piece of data to set. |
Returns
Type | Description |
---|---|
string | The value at the named data store. |
Example
import { parseHTML } from 'k6/html';
import { sleep } from 'k6';
export default function () {
const content = `
<h1 data-test-id="data-value">Hola</h1>
`;
const doc = parseHTML(content);
const sel = doc.find('h1');
console.log(sel.data().testID);
console.log(sel.data('test-id'));
console.log(sel.data('testId'));
sleep(1);
}