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 6881111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:03:58+00:00 2026-05-27T05:03:58+00:00

I have this HTML and I’m trying to return false on click if the

  • 0

I have this HTML and I’m trying to return false on click if the element contains specific text.

This is my HTML:

<ul>
    <li id="1"></li>
    <li id="2"></li>
    <li id="3"></li>
    <li id="4"></li>
    <li id="5"></li>
    <li id="6">text</li>
    <li id="7"></li>
</ul>

Javascript:

$("ul").on('click', 'li', function (e) {
    var value = $(this).attr('id');
    if ("#" + value + ":contains(\"text\")"){  // Something similar to this
        return false;
    };
    alert('test');
});

How can I return false, if the element contains the word ‘text’.

Example: http://jsfiddle.net/wSvLD/ (this returns false on everything)

  • 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-05-27T05:03:59+00:00Added an answer on May 27, 2026 at 5:03 am

    You’ll need to escape those quotes in contains(“text”)

    Or use single quotes in combination with double quotes….

    Also, the value var should be inside the event function.

    EDITS:

    $("li").click(function (e) {
    
        var value = $(this).attr('id');
    
        if ( $('#' + value + ':contains("text")').length != 0 ){ 
            return false;
        }
    
        alert('test');
    
    });
    

    :contains returns a jQuery object, so you need to check the length of the object to see if it contains a match.

    http://jsfiddle.net/8NuvP/

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

Sidebar

Related Questions

I have this html page which is very simple, it contains a text box
have this html: <div id=editable contentEditable=true > <span contentEditable=false >Text to delete</span> </div> need
I have this HTML dropdown: <form> <input type=text id=realtxt onkeyup=searchSel()> <select id=select name=basic-combo size=1>
i have this html <ul> <li><form action=# name=formName></li> <li><input type=text name=someName /></li> <li><input type=text
I have this html code: <tr> <td><label><input type=text name=id class=DEPENDS ON info BEING student
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this html: <dl> <dt>some text</dt> <dd>12.45</dd> <dt>some larger text</dt> <dd>46.05</dd> <dt>some even
I have this HTML: <input type=text name=textField /> <input type=submit value=send /> How can
I have this html div tag defined: <div style=height:100px; width:100px class=total-title> first text </div>
I have this HTML/CSS code ( JSBin ): .trackTime{width:50px; text-align:left; float:left;} .trackInputTime{width:45px; height:22px; background-color:#F4F4F4;}

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.