Click here to Skip to main content
11,707,167 members (59,832 online)
Rate this: bad
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 15:35pm
enhzflep at 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;
Sergey Alexandrovich Kryukov at 3-Oct-12 22:34pm
Good point. I think, with any thinkable state of affairs, using not HTML predefined tag makes no sense at all.
Peter_in_2780 at 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
0 OriginalGriff 141
1 Sergey Alexandrovich Kryukov 135
2 chainerlt 110
3 Maciej Los 80
4 ppolymorphe 79
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,512
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696

Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2015
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