Exchange data-src for CRS

Asked

Viewed 750 times

2

Good afternoon to all!

I have a question, it may be simple (or not).

You can change attributes?

Example, I have an img tag with a data-src attribute. I want to turn this data-src attribute into src.

Thus:

<img id="teste" data-src="link_da_imagem">

I want it that way:

<img id="teste" src="link_da_imagem">

Do you have any Javascript/Jquery function that does this?

Thank you!

EDIT

William, thank you!

The problem is, I’ll try to describe.

I have a store, that the products to sample, stay like this: http://image.prntscr.com/image/4b9f2d57b2734a38ad11ca8f86f53157.png

When you click on the small image, the big image changes (Changes in the case, to which small image you clicked)

I need, instead of looking like this, to have a carousel there, to move the images to the side, instead of clicking on the image and changing it. In case, stay like this: http://image.prntscr.com/image/5a895102389440d58526fc1e7f13361f.png

I’m using Owl-Carousel, which in this case is the script: http://owlgraphic.com/owlcarousel/demos/one.html

In the store, this products here: http://image.prntscr.com/image/4b9f2d57b2734a38ad11ca8f86f53157.png Only the large image is in SRC, the small ones (left side) are with data-src, so the Carousel does not work, put it shows only the tag that has SRC and not DATA-SRC. If you understand and can help, I appreciate it, if not, thank you in the same way! :)

  • 1

    Why do you wear data-src instead of src?

  • Do you use any library? By default the right is src.

  • 1

    Just edit the HTML, no?

  • Look at my edited question, if you can, and if you can understand. Thank you!

1 answer

2

In your case it can be this way (Solution with jQuery):

$('#teste').attr({
        src : $('#teste').attr('data-src'),
    })
    .removeAttr('data-src')
;

Basically, you will create a new attribute and remove the old one, I think renaming exactly is not possible.

  • 2

    No point in posting a code, it must be using a system of ready, in logic it should change from data-src to src alone, or maybe it is just fixing the HTML, no use posting answers without having any idea of the real root of the problem. Understand as a constructive criticism.

  • Thanks William for the reply, #EDITED

  • @Lucascarvalho actually the comment is for Kenny

  • Guilherme, that’s what you described, I’m using the Owl-Carousel, which in this case the script is here: http://owlgraphic.com/owlcarousel/demos/one.html the data-src is already from the system, and I can’t change them to src in html, it would have to be via Javascript.

Browser other questions tagged

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