Javascript gets the url value in the background attribute, and js gets the backgroundurl

Source: Internet
Author: User

Javascript gets the url value in the background attribute, and js gets the backgroundurl

Preface

Recently, when I was working on a project, I encountered a problem. I needed to obtain the address of a dynamic preview image. This is not a problem. The path of the image is mainly written in css.Background-imgAttribute, so I decided to use js to get the content in its url. I will share with you the solution below. If you need it, let's take a look.

Var avatar = $ ("# image-preview" ).css ("backgroundImage"); alert (avatar );

Obtain includeUrl(“xxx.jpg ")Format value, so I checked the information and found to only getXxx.jpgMethod of form value:

Var avatar = $ ("# image-preview" ).css ("backgroundImage"); avatar = avatar. split ("(") [1]. split (")") [0]; alert (avatar );

The obtained value is the image address.

Summary

The above is all about this article. I hope the methods shared in this article will be helpful for you to learn or use Javascript. If you have any questions, please leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.