Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8373127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:36:08+00:00 2026-06-09T14:36:08+00:00

I was goofing around and trying some regular expressions for the sake of experimenting

  • 0

I was goofing around and trying some regular expressions for the sake of experimenting and I was doing it on the console at bestbuy.com. Suddenly I decided to make things a bit more sophisticated and then the trouble started. My code is supposed to add a button that will highlight the found matches for the regex in question if that button does not exists in the site already, but it’s not working, you can test is at best buy yourselves. Here it is:

var rExpIni = /^\b(?:[A-Z][^aeiou\d\s][a-z]{2})\b\s\b(?:[A-Z][a-z]{2}|[a-z]{3})\b/gm;
var rExp = /\b(?:[A-Z][^aeiou\d\s][a-z]{2})\b\s\b(?:[A-Z][a-z]{2}|[a-z]{3})\b/gm;

function sim(){
    $("p, a, span, em, i, strong, b, h1, h2, h3, td, th, hr").each(function(){
        if( rExpIni.test($(this).text()) == true){
            $(this).css({
                "background-color":"#DDBB22",
                "border-style":"outset",
                "border-width":"3px",
                "border-color":"#DDBB22",
                "font-size":"12pt",
                "font-weight":"bold",
                "color":"red"
            });
        }
    });
    $("img").each(function(){
        if( rExp.test($(this).attr("title")) == true || rExp.test($(this).attr("alt")) == true ){
            $(this).css({
                "border-style":"inset",
                "border-width":"10px",
                "border-color":"#DDBB22",
                "font-size":"12pt",
                "font-weight":"bold",
                "color":"red"
            });
        }
    });
}

function nao() {
    $("p, a, span, em, i, strong, b, h1, h2, h3, td, th, hr, img").each(function(){
        $(this).css({
            "background-color":"",
            "border-style":"",
            "border-width":"",
            "border-color":"",
            "font-size":"",
            "font-weight":"",
            "color":""
        });
    });
}
$(document).ready(function(){
    if($("body:not(body:has(button#but))")){
        var nBotao = $("<button id=\"but\">Procurar</button>");
        $("body").prepend(nBotao);
    }
});
$("#but").toggle(sim(),nao());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:36:10+00:00Added an answer on June 9, 2026 at 2:36 pm

    You can use the jQuery object’s length property:

    if ($('#but').length == 0) {
        var nBotao = $("<button id='but'>Procurar</button>");
        $("body").prepend(nBotao);
    }
    

    Also as you are generating the element dynamically you should delegate the event:

    var which = true;
    $(document).on('click', '#but', function() {
         if (which) {
             sim()
             which = false;
         } else {
             nao()
             which = true;
         }
    })
    

    Please note that toggle() method is deprecated and you should put all the codes inside the $(document).ready();

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just goofing around with java when i thought of trying to get
In goofing around with some F# (via MonoDevelop), I have written a routine which
I'm goofing around with some HTML5 stuff and wanted to combine the Close Pixelate
Complete noob to C , just getting started with some goofing around, wondering how
I'm goofing around with the new youtube as3 API but got stuck. This is
Im goofing around with XNA and I've come to the part where I need
https://i.stack.imgur.com/YZXZN.png (I'm currently not allowed to embed images) I could really use some help
I am goofing around with pointers and structures. I want to achieve the following:
So I'm goofing around with a prototype for a text adventure. I created a
I have the following code which does nothing but reading some values from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.