Hide image generated by Javascript

Asked

Viewed 465 times

9

I am using the sharethis plugin to share content on social networks. For this I am making the following call:

<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=YOUR_PUBLISHER_ID"></script> 

The problem is that this code generates an image, and I wanted to use some images of my sharing:

<img width="125" border="0" height="16" alt="Share" src="//ct1.addthis.com/static/btn/v2/lg-share-pt.gif"></img>

Is it possible to hide the image in javascript? To hide the image I am trying this way but it does not work:

<script>
 $('#teste2').find('img[src$="//ct1.addthis.com/static/btn/v2/lg-share-pt.gif"]').css('visibility', 'hidden');
</script>

I found this example on the net, and I was able to modify it to what I wanted. But in this case I’m not succeeding, I don’t know if it will be by way of the generated image.

http://jsfiddle.net/bTf7K/162/

The point is that my images appear correctly and do the sharing, but the image is also added to the top and I wanted to hide it.

3 answers

8


I suggest searching the images that have the shareit domain in their url (src) and hiding them.

$('.sortEleWrapper img').each(function () {
    if (this.src.split('addthis.com/static/')[1]) this.style.display = 'none';
});

In this case I used the .sortEleWrapper as ancestral/parent element, but if there is a closer meljor. The idea is to search all the images inside this element and its descendants and hide those who have a part of the src containing this string addthis.com/static/

Example

Another idea is to put the script inside a div "shield"/wrapper and put in the CSS a rule to hide images that are there with #escudo img{display: none;}

Example

  • This works well, the problem is that it is loading the sharethis image in order to load the page (I think). So you’re not hiding my image

  • @pc_oc, I added another idea.

  • 1

    I got it from the last idea. Thanks again!

5

One idea would be to include the script making use of the $.getScript() in order to include the sharethis plugin on the page.

This way you can be aware and know when it was loaded, thus running the code to locate and hide the image:

var endereco = "http://s7.addthis.com/js/250/addthis_widget.js#username=YOUR_PUBLISHER_ID";

$.getScript( endereco )
.done(function( script, textStatus ) {
    // correu bem, localizar e esconder imagem que contém X
    $("img[src*='addthis.com']").hide();
})
.fail(function( jqxhr, settings, exception ) {
    // correu mal, agir em conformidade
});

Useful information:

0

Your code is not complete.

But try to make the change by CSS.

.st_sharethis_custom{
   background: url("imagem.jpg") no-repeat;
   padding:0px 16px 0 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.