{"record":{"id":"38cd90ce30fd5f8c","repo":"oxc-project/oxc","slug":"the-a-element-has-href-and-onclick","errorCode":null,"errorMessage":"The `a` element has `href` and `onClick`.","messagePattern":"The `a` element has `href` and `onClick`\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/jsx_a11y/anchor_is_valid.rs","lineNumber":41,"sourceCode":"        format!(\"Provide the `{}` attribute for the `a` element.\", valid_attrs[0].as_ref())\n    } else {\n        let list =\n            valid_attrs.iter().map(|a| format!(\"`{}`\", a.as_ref())).collect::<Vec<_>>().join(\", \");\n        format!(\"Provide one of these attributes for the `a` element: {list}\")\n    };\n    OxcDiagnostic::warn(\"Missing `href` attribute for the `a` element.\")\n        .with_help(help)\n        .with_label(span)\n}\n\nfn incorrect_href(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use of incorrect `href` for the 'a' element.\")\n        .with_help(\"Provide a correct `href` for the `a` element.\")\n        .with_label(span)\n}\n\nfn cant_be_anchor(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"The `a` element has `href` and `onClick`.\")\n        .with_help(\"Use a `button` element instead of an `a` element.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct AnchorIsValid(Box<AnchorIsValidConfig>);\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct AnchorIsValidConfig {\n    /// Custom components to treat as anchor elements.\n    components: Vec<CompactStr>,\n    /// Custom prop names to treat as link destinations.\n    special_link: Vec<CompactStr>,\n    /// Sub-rule aspects to run.\n    aspects: Option<Vec<AnchorIsValidAspect>>,\n}\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/jsx_a11y/anchor_is_valid.rs#L23-L59","documentation":"Fires from jsx-a11y/anchor-is-valid when an anchor element has both an href and an onClick handler, meaning it is used as a button. Screen readers may announce it as a link while it behaves like a button; the cant_be_anchor helper reports the span and advises using a button element instead.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/jsx_a11y/anchor_is_valid.rs:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a `<button type=\"button\">` element instead of the anchor","Remove the onClick handler if the anchor is meant to navigate"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}