Click here to Skip to main content
12,819,538 members (28,813 online)
Rate this:
Please Sign up or sign in to vote.
See more: Javascript HTML jQuery
I am using javascript to highlight text in markup. I can successfully change the markup, as seen in the browser developer tool (chrome), but rendered code as appears in browser window does not change. Does anyone see what i am doing wrong?

<script type="text/javascript">
    $(document).ready(function (e) {
        $('#submit').click(function (e) {
            try {
                var $inputTxt = $('#search');
                result = $inputTxt.val();

        $('p').each(function () {

            var a=$(this).html().toString();
            var aindx=[];

            while(a.indexOf(result) >
Posted 3-Oct-12 16:35pm
enhzflep 3-Oct-12 22:24pm
I see that you're using a tag, <mark/> - one I've not seen before. Some browsers used to disallow styling of non-standard elements, I've no idea on the current state of affairs.
If the HTML is changing, but the display isn't - I'd look at the CSS to check the style of 'mark' elements.

Even quicker, just add something like the following to your css:

background-color: yellow;
Good point. I think, with any thinkable state of affairs, using not HTML predefined tag makes no sense at all.
Peter_in_2780 4-Oct-12 1:30am
Why not use <span> insted of <mark> ?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

is a standard HTLML5 tag used to highlight text.

The intention here was to insert the mark tag into the text to display the searched for text as highlighted.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100