Menu
Open source

Selection.data([key])

Return the value at the named data store for the first element in the set of matched elements. Mimics jquery.data

ParameterTypeDescription
key (optional)stringA string naming the piece of data to set.

Returns

TypeDescription
stringThe value at the named data store.

Example

JavaScript
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);
}