Expected an identifier and instead saw '>'
If you are a beginner in coding, then you might have come across this error message "Expected an identifier and instead saw '>'". This error message usually appears when you have incorrectly written your HTML code.
The ">" character is used in HTML to close a tag. For example, the correct way to write a paragraph tag is:
<p>This is a paragraph</p>
If you forget to add the closing ">" character, you will get this error message.
Another common mistake that results in this error is when you use the wrong type of quotes. In HTML, you can use either single quotes or double quotes to enclose attribute values. However, you cannot mix and match them. For example:
In the above example, the code has used single quotes to start the href attribute, but double quotes to end it. This results in an error because the browser is expecting an identifier after the ">" character, but instead it sees another character which it cannot interpret.
How to Fix It
The best way to fix this error is to check your code for any missing or mismatched tags, and ensure that you are using the correct type of quotes. Use an HTML validator tool to check your code for errors before publishing it online.
Here's how you can use highlight.js for syntax highlighting:
- First, include the highlight.js library in your HTML file.
- Then, add the "hljs" class to the code block that you want to highlight.
- Finally, call the highlightBlock() function to highlight the code block.
Here's an example:
<html> <head> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/styles/default.min.css" integrity="sha512-kBc5+5W8JvKkzBpZD+g+jM4W6X4xKjR+toIbY6YkWjKvJfL1WN+Zq3nmqKj9XNsQJQy1kC0z3qD3Pk+vlwQ2RQ==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.2.0/highlight.min.js" integrity="sha512-HVYiM8u8wVrMOMLdJiVQhftD9e7xZDTKjplBnTEq3sVDn8wAtQ2LhjZtTnTtT9FtVxT+RPGMgGmIhAe8aMwMtA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script>hljs.highlightAll();</script> </head> <body> <pre><code class="html hljs"><p>This is a paragraph</p></code></pre> </body> </html>
In the example above, the code block is enclosed in the "pre" and "code" tags, and it has the "html" class which tells highlight.js to highlight the code as HTML. The "hljs" class is added to the "code" tag to enable syntax highlighting. Finally, the "highlightAll()" function is called to highlight all code blocks on the page.