Click here to Skip to main content
12,294,775 members (59,022 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();
                alert(result);
 

        $('p').each(function () {
 
            var a=$(this).html().toString();
            var aindx=[];
 
            while(a.indexOf(result) >
Posted 3-Oct-12 15:35pm
Comments
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:

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

1 solution

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

Solution 1

<mark>
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.
  Permalink  
v2

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
Web02 | 2.8.160525.2 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2016
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