javascript - Userscripts to Remove a div by css -


i want remove div userscripts possible thing differ div bacground image in inline css.

suppose div has following css: (background-image:http://www.example.com/example.png)

could me that?

i have tried following 1 not working.

var baddivs = $("div div:contains('background-image')"); baddivs.remove (); 

use:

$("div").each(function() {   if ($(this).css("background-image") != 'none') {     $(this).remove();   } }); 

documentation: .each(), .css(), .remove().

warning!! checking div huge work, should use class tocheck instead. so:

$(".tocheck").each(function() {   if ($(this).css("background-image") != 'none') {     $(this).remove();   } }); 

working demo.

$(".tocheck").each(function() {    if ($(this).css("background-image") != 'none') {      $(this).remove();    }  });
div {    border:1px solid #000;  }    .tocheck {    width: 100px;    height: 100px;  }    #withimage {    background-image: url("http://www.placehold.it/100/100");  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <div class="tocheck" id="withimage">    div check image  </div>    <div class="tocheck">    div check without image  </div>    <div>    normal div  </div>

update:

since class tocheck partial-variable need more tricky script using regular expression. first need extend jquery selectors (tutorial) :regex:

jquery.expr[':'].regex = function(elem, index, match) {     var matchparams = match[3].split(','),         validlabels = /^(data|css):/,         attr = {             method: matchparams[0].match(validlabels) ?                          matchparams[0].split(':')[0] : 'attr',             property: matchparams.shift().replace(validlabels,'')         },         regexflags = 'ig',         regex = new regexp(matchparams.join('').replace(/^\s+|\s+$/g,''), regexflags);     return regex.test(jquery(elem)[attr.method](attr.property)); } 

then use variable class:

$("div:regex(class, profile_view_img_+[0-9]*)").each(function() {   if ($(this).css("background-image") != 'none') {     $(this).remove();   } }); 

updated demo.

jquery.expr[':'].regex = function(elem, index, match) {      var matchparams = match[3].split(','),          validlabels = /^(data|css):/,          attr = {              method: matchparams[0].match(validlabels) ?                           matchparams[0].split(':')[0] : 'attr',              property: matchparams.shift().replace(validlabels,'')          },          regexflags = 'ig',          regex = new regexp(matchparams.join('').replace(/^\s+|\s+$/g,''), regexflags);      return regex.test(jquery(elem)[attr.method](attr.property));  }    $("div:regex(class, profile_view_img_+[0-9]*)").each(function() {    if ($(this).css("background-image") != 'none') {      $(this).remove();    }  });
div {    border:1px solid #000;  }    .tocheck {    width: 100px;    height: 100px;  }    #withimage {    background-image: url("http://www.placehold.it/100/100");  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <div class="profile_view_img_22222222" id="withimage">    div check image  </div>    <div class="profile_view_img_1111111">    div check without image  </div>    <div>    normal div  </div>


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -