how to bring highlight js into pre tag in a whole angularjs application?

Published

I have an angularjs app for students to learn it includes so many html pre tags and code snippets in it. It have highlight js but some of the syntaxes aren’t showing exact colours. but i have added window.onload function in one of the usecases and it works, properly. the thing i want ; is to apply it globally on all pre tags but it didn’t work with jquery code i’ve written. to more reference I’m adding both codes and image here

working model
working model

on other use cases

on other use cases

code i’ve added which giving result

window.onload = function() {
                var aCodes = document.getElementsByTagName('pre');
                for (var i=0; i < aCodes.length; i++) {
                    hljs.highlightBlock(aCodes[i]);
                }
            };

code i’ve tried (if it works i’ll make it global)

$("pre").on("load", function() {
                setTimeout(function () {
                    var aCodes = document.getElementsByTagName('pre');
                    for (var i=0; i < aCodes.length; i++) {
                        hljs.highlightBlock(aCodes[i]);
                    }
                },1000)
            })

what i’m missing? is there any other ways to solve this

Source: AngularJS Questions

Published
Categorized as angularjs, html, javascript, jquery Tagged , , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq