Jump to content

Select all SPAN elements which contain a "foobar" property? If possible with jQuery


pstein

Recommended Posts

How can I select all SPAN elements in current webpage which contain a property "foobar"?

The assigned value is unimportant.

So elements like the following should be matched:

<span aaa="bbb" foobar="23452345" .....>...</span>

I tried:

$('span[foobar^=""]').remove();

but it didn't work

Edited by pstein
Link to comment
Share on other sites

Posted (edited)

Your solution is NOT working.

Lets see a simplified example:

https://www.makeuseof.com/how-to-take-screenshots-on-android-when-the-app-doesnt-allow-it/

I want to get rid of an advertising block on the right (see attached snapshot). which starts with:

<div id="K84X2hsVZN" data-ub-carousel="true" 

Therefor I setup a Greasemonkey script like

// ==UserScript==
// @name            ChangeLayoutMakeuseof
// @namespace       nsChangeLayoutMakeuseof
// @description     Change Layout makeuseof.com
// @match           https://*.makeuseof.com/*
// @exclude-match   https://*.makeuseof.com/
// @exclude-match   https://*.makeuseof.com/category/*
// @version         2.14.1
// @grant           GM_addStyle
// @require         http://code.jquery.com/jquery-latest.js
// ==/UserScript==

$('div').attr('data-ub-carousel').remove();

setTimeout(function(){

$('div').attr('data-ub-carousel').remove();

  }, 5000);

After adding the user script and reloading the webpage, the ad persist.

Any other suggestion?

https://s20.directupload.net/images/240314/gm2z76xs.png

Edited by pstein
Link to comment
Share on other sites

As it is a carousel it probably is looping to add a new ad at a set time. So it might be better to hide than remove. As your script only runs once after 5sec it catch first one only, unless you use setInterval then it will repeat every 5 sec. To reduce repeating loops check this element exists by checking length.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...