SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Location
    Taiwan
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expression with jQuery codes?

    How do I use the following regular expression with jQuery codes?


    document.body.innerHTML = document.body.innerHTML.replace(/\<hr (class="?seperator"?)\s?\/?\>/ig,'<div $1></div>');

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Before you do anything else, please correct the spelling to separator. Also, is this DIV going to be empty? If you're just using it as an empty separator, that's not appropriate use of the element (HR is better, or just CSS). Anyway, what you're after is simple enough:

    Code javascript:
    $('hr.separator').replaceWith('<div class="separator"></div>');

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Location
    Taiwan
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    Before you do anything else, please correct the spelling to separator. Also, is this DIV going to be empty? If you're just using it as an empty separator, that's not appropriate use of the element (HR is better, or just CSS). Anyway, what you're after is simple enough:

    Code javascript:
    $('hr.separator').replaceWith('<div class="separator"></div>');
    Thank you. I mean I want to use regular expression in jQuery, rather than replace regular expression with jQuery manipulation codes. For example: (I know this doesn't work, just showing what I mean)

    $('body').html($('body').html().replace(/\<hr (class="?separator"?)\s?\/?\>/ig,'<div $1></div>'));



    P.S. The code at the very beginning is just an example showing what kind of code I want to use jQuery to replace with. I never write <hr class="seperator" /> or <div class="separator"></div> in the HTML source.

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Location
    Taiwan
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raffles View Post
    Before you do anything else, please correct the spelling to separator. Also, is this DIV going to be empty? If you're just using it as an empty separator, that's not appropriate use of the element (HR is better, or just CSS). Anyway, what you're after is simple enough:

    Code javascript:
    $('hr.separator').replaceWith('<div class="separator"></div>');
    Thank you. I mean I want to use regular expression with jQuery, rather than replace regular expression with jQuery manipulation codes. For example: (I know this doesn't work, just showing what I mean)

    $('body').html($('body').html().replace(/\<hr (class="?separator"?)\s?\/?\>/ig,'<div $1></div>'));



    P.S. The code at the very beginning is just an example showing what kind of regular expressioin I want to use with jQuery. I never write <hr class="seperator" /> or <div class="separator"></div> in the HTML source.

  5. #5
    SitePoint Guru whisher's Avatar
    Join Date
    May 2006
    Location
    Kakiland
    Posts
    732
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Just for the sake of it
    Code JavaScript:
    console.log($('body').html().toString().replace(/\<hr (class="?separator"?)\s?\/?\>/ig,'<div $1></div>'));
    I prefer the other way
    Bye.

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Location
    Taiwan
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by whisher View Post
    Hi,
    Just for the sake of it
    Code JavaScript:
    console.log($('body').html().toString().replace(/\<hr (class="?separator"?)\s?\/?\>/ig,'<div $1></div>'));
    I prefer the other way
    Bye.
    Thank you. Is consol.log a Firebug related code?



    Can someone explain what consol.log is?

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    console.log is a common way to record information to the javascript log. It's common across Firefox, Google Chrome, and Opera.

    There is also for IE a faux console that you can use too.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •