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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:36:53+00:00 2026-06-05T23:36:53+00:00

I use something like this to click an element on a page by condition:

  • 0

I use something like this to click an element on a page by condition:

var findElem = function(elems, text) {
    for (var i = 0; i < elems.length; i++) {
        if (elems[i].textContent == text) {
            return elems[i];
        } else {
            var result = findElem(elems[i].children, text);
            if (result != undefined) {
                return result;
            }
        }
    }
    return;
}

switch (document.getElementById('my_id').value) {
    case "1":
        findElem(document.documentElement.children, "blabla1").click();
        break;
    case "2":
        findElem(document.documentElement.children, "blabla2").click();
        break;
    default:
        break;
}

I want to add one more condition to this code.

Page I’m working is something like this:

<body id="something">

<div id="something2" class="container">
    <div id="header">
        <a class="hmm" href="somelink"></a>
        <a class="aname" target="_blank" href="anotherlink"></a>
    </div>

    <div id="anotherthing" class="anotherthing2">

<div class="differentthing " style="left: 2px; ">
    <div class="asdafad"></div>
</div>

I have to look if differentthing has no style

in short I want to do something like this:

switch (document.getElementById('my_id').value) {
    case "1":
        ---if differentthing has no style attrib then---
        findElem(document.documentElement.children, "blabla1").click();
        break;

so if differentthing section of page is like this

<div class="differentthing ">

then do findElem.click thing.

if it’s <div class="differentthing " style="left: 2px; "> then do nothing.

I hope I can describe. How can I do that? And sorry for my bad english.

  • 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-05T23:36:54+00:00Added an answer on June 5, 2026 at 11:36 pm
    switch (document.getElementById('my_id').value) {
        case "1":
            // getting an array of elements with "differentthing" class
            var elements = document.getElementsByClassName("differentthing");
    
            // if there is just one and it does not have "style" attribute
            if (elements.length == 1 && !elements[0].getAttribute("style")){
                // perform some action
                findElem(document.documentElement.children, "blabla1").click();
            }        
            break;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this `$(function(){$(.signaler).click(function(){var element=$(this);var I = element.attr(id);var page = $('#page').attr('value');var info = id=+I+& page=+
I have something like this: $('element.selector').live(click, function (){ run_some_func (); }); $('element.selector2').live(click, function (){
Is it possible to use something like this wrapper with fluent configuration? http://jeffreypalermo.com/blog/use-this-nhibernate-wrapper-to-keep-your-repository-classes-simple/ If
When I want to show an image I use something like this: public ActionResult
Hay guys, i want to use something like this users = User.objects.all() but i
I want to delete all rows in a datatable. I use something like this:
I have some folder with different files. I want to use something like this:
Should I use something like maven for this? Or would finding them as they
What Swing class can I use to implement something like this? Add To List
I would like to do something like this i.e., use wild card characters in

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.