Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make find and replace in page using jQuery?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 465
    Comment on it

    Hello Readers. If you want to make replacement of words on any webpage then jquery offers you to do this. The benefit of using the Jquery is to run code on real time front end.

    So let's get started working on it.
    Step 1:  Create a simple HTML page with a long text data. You can also write the code of  your from in English version and can make it's replacement for any other language. It's code will go like this:-

     

    <tr>
                   <td class="firstCol">
                    Doors               </td>
                    <td id="attribute100"><select name="doors" required=""><option value="I don't know"> - I don't know</option><option value="1 Door"> - 1 Door</option><option value="2 Doors"> - 2 Doors</option><option value="3 Doors"> - 3 Doors</option><option value="4 Doors"> - 4 Doors</option><option value="5 Doors"> - 5 Doors</option><option value="More"> - More</option></select></td>
              </tr>



    Now you just have  to create a simple jquery file and paste the words with their replacements and it's code will go like this:-

    <script type="text/javascript">
    var replaced = $(".table").html().replace(/Make/g, '').
    replace(/Model Detail/g, ' ').
    replace(/Model Detail/g, ' ').
    replace(/Year/g, ' ').
    replace(/Kilometers/g, '').
    replace(/Exterior colour/g, ' ').
    replace(/- i don't know/g, ' ').
    replace(/- 1 door/g, ' ').
    replace(/- more/g, '').
    replace(/Kilometres/g, '').
    replace(/Doors /g, ' ').
    replace(/Features/g, '').
    replace(/WOF expires/g, ' WOF').
    replace(/ - ABS brakes/g, ' ABS').
    replace(/- Air conditioning/g, '').
    replace(/- Alarm/g, '').
    replace(/- Alloy wheels/g, '').
    replace(/Body Style/g, ' ').
    replace(/Engine size/g, ' ').
    replace(/Mize Inspection/g, ' ').
    replace(/Imported/g, '').
    replace(/test/g, 'test').
    replace(/tyre size/g, ' ').
    replace(/Enter/g, '');$('.table').html(replaced);</script>

    In the code script above you can see the words are written inside the brackets. And its replacement is written against it in the Arabic language. So by using find and replacement technique this is making my  page multilingual also. In the run time, the English words will be replaced by Arabic word as given. 


    Now you can decide when to load this file in run time and replacement can be seen on a web browser. Output of the code can be seen in the screenshot attached.

    How to make find and replace in page using jQuery?

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: