Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/__fixtures__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export const unwrapspans: string = [
].join('');

export const inputs: string = [
'<button id="btn-value" value="button">Button</button>',
'<button id="btn-valueless">Button</button>',
'<select id="one"><option value="option_not_selected">Option not selected</option><option value="option_selected" selected>Option selected</option></select>',
'<select id="one-valueless"><option>Option not selected</option><option selected>Option selected</option></select>',
'<select id="one-html-entity"><option>Option not selected</option><option selected>Option &lt;selected&gt;</option></select>',
Expand Down
19 changes: 18 additions & 1 deletion src/api/attributes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,23 @@ describe('$(...)', () => {
const element = $('select#multi').val(['1', '3', '4']);
expect(element.val()).toHaveLength(3);
});
it('(): on button should get value', () => {
const val = $('#btn-value').val();
expect(val).toBe('button');
});
it('(): on button with no value should get undefined', () => {
const val = $('#btn-valueless').val();
expect(val).toBeUndefined();
});
it('(value): on button should set value', () => {
const element = $('#btn-valueless').val('newValue');
expect(element.attr('value')).toBe('newValue');
expect(element.val()).toBe('newValue');
});
it('(value): on button with existing value should update it', () => {
const element = $('#btn-value').val('updated');
expect(element.attr('value')).toBe('updated');
});
});

describe('.removeAttr', () => {
Expand Down Expand Up @@ -1025,7 +1042,7 @@ describe('$(...)', () => {
it('(fn) : should no op elements without attributes', () => {
const $inputs = $(inputs);
const val = $inputs.removeClass(() => 'tasty');
expect(val).toHaveLength(15);
expect(val).toHaveLength(17);
});

it('(fn) : should skip text nodes', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/api/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ export function val<T extends AnyNode>(
: option.attr('value');
}
case 'input':
case 'option': {
case 'option':
case 'button': {
return querying
? this.attr('value')
: this.attr('value', value as string);
Expand Down