Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to highlight certain words in a html file using jquery and highlight.js.
I know nothing about jquery and this code I've been working wiith is not highlighting.
Could anyone tell me whats wrong and explain jquery?
HTML
<!doctype html>
<link rel="stylesheet" href="/path/to/styles/default.css">
<script src="/path/to/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<html lang="en">
<head>
  <meta charset="utf-8">
  <title>css demo</title>
  <style>
  div {
    width: 20px;
    height: 15px;
    background-color: #f33;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<div>bog are for frogs and click</div>
<p>Hello maybe this is a click</p>
 
<script>
$(document).ready(function() {
  $("div ,p").each(function(i, block) {
    hljs.highlightBlock(block);
  });
});
</script>
 
</body>
</html>



[Edit member="Tadit"]
Added pre tags.
[/Edit]
Posted
v2
Comments
CHill60 1-Jun-15 4:37am    
As you have posted this now with proper formatting I suggest you delete this version before you get too many reports for reposting
Andy Lanng 1-Jun-15 4:45am    
You can use the "Improve question" button above these comments to update a question instead of re-posting it

1 solution

highlight.js is a SYNTAX highlighting library...It is not for highlighting selected words or phrases...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900