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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:54:19+00:00 2026-05-17T00:54:19+00:00

So I have captured the ID of an image in a jquery variable like

  • 0

So I have captured the ID of an image in a jquery variable like so:

$("#tag img").click(function(e) {       
    var element = $(this).attr("id");

How do I then parse the var element?

I would like to put it in an if statement like this:

if ( $(element *= 'square' ) {
    $('#tag #view_name').text("Tag with a Square");
}
elseif ($(element *= 'circle' ) {
    $('#tag #view_name').text("Tag with a Circle");
} 

How do I do that, with the least amount of code possible?

Thanks.

Edit: Oh, and the text I am searching for are the two strings in the single quotes (‘square’ and ‘circle’).

Edit: All of the answers below look like they should be working…but they aren’t. Here is the other code, so you guys can see if I am missing something:

<div id="tag">
        <a href=""><img src="images/square.png" id="square-tag"></a> | 
        <a href=""><img src="images/circle.png" id="circle-tag"></a> |      
        <span id="view_name">Tag with Square</span>
    </div>  

Edit 3: Ok…it seems that some other jQuery was hijacking that div. All the answers are right. I wish I could mark all of them correct 🙂

  • 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-17T00:54:20+00:00Added an answer on May 17, 2026 at 12:54 am

    This is similar to $("input[name*='man']") selector (example from your comment)

    var name = $(this).attr("name");
    if (name.indexOf('square') >= 0) {
        $('#tag #view_name').text("Tag with a Square");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: $('.be-delete').live('click', function(e){ e.preventDefault(); var object =$(this); var url = $(this).attr('href');
I have this jquery code: <script> $(function() { $( #sortable ).sortable({ stop: function(event, ui)
I am using this jquery navigation: http://css-tricks.com/5582-jquery-magicline-navigation/ I would like to have the navigation
I have an image with a click event handler that captures the location where
I have one audio file captured from my iphone. I want to upload this
I have some JQuery where when you click on a Add to Basket button
I'm working on a Javascript/jQuery powered image preloader, and have hit a bit of
I have developed an application that in the end will save a captured image
I have a class skImage. This class has a private variable (with a public
I have an Web-application in which I capture Image using EdgeCamShots Sample Application Saving

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.