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
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
10 changes: 9 additions & 1 deletion src/api/attributes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,14 @@ describe('$(...)', () => {
expect($('<div>').val()).toBeUndefined();
});

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('(): on select should get value', () => {
const val = $('select#one').val();
expect(val).toBe('option_selected');
Expand Down Expand Up @@ -1013,7 +1021,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
1 change: 1 addition & 0 deletions src/api/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ export function val<T extends AnyNode>(
? option.toArray().map((el) => text(el.children))
: option.attr('value');
}
case 'button':
case 'input':
case 'option': {
return querying
Expand Down