-1

I want to do this using jQuery at once.

var elem = document.createElement("img");
    
elem.setAttribute("src", "http://example.com/something.jpeg");
elem.setAttribute("height", "100%");
elem.setAttribute("width", "100%");
2

1 Answer 1

0
$('img').attr({'src':'http://example.com/something.jpeg', 'height':'100%', 'width':'100%'});

$('img') <= coresponding HTML element which you want to set the attributes

.attr(
    {
        'htmlAttributeName': 'attributeValue',
        'anotherHtmlAttributeName': 'attributeValue',
        ....
    }
)
Sign up to request clarification or add additional context in comments.

2 Comments

Code-only answers are not particularly helpful. Please add some descriptions of how this code solves the problem.
@LizeshShakya OK, I edited my answer with code description

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.