If I have an element "img" id = "myimg".It is possible to add a link to "img" without editing the html page using jQuery
<img id="myimg" src="image.png">
I like to make "myimg" have a link like this.
<a href="test.html"><img id="myimg" src="image.png"></a>
You can use wrap() :
wrap()
$("#myimg").wrap("<a href='test.html'></a>');
or
$("#myimg").wrap($("<a>").attr("href", "test.html"));
var a = $("<a>").attr("href", "test.html"); $("#myimg").wrap(a);
I am not in jQuery. Using Javascript, you can do something like:
var parentEl = document.getElementById("myimg").parentElement; var imgEl = parentEl.innerHtml; parentEl.innerHtml = '<a href="test.html">' + imgEl + '</a>';
$(document).ready(function() { var src = "linkhere.html"; var a = $("<a/>").attr("href", src); $("#myimg").wrap(a); });
Source: https://habr.com/ru/post/1303436/More articles:Is there a way to notify when a property changes in a QObject? - propertieshttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1303432/push-to-a-mercurial-repository-bitbucket-produces-request-entity-too-large&usg=ALkJrhjILlkOJ3LUwPkF2vny6a2N5F9BXwHow to integrate Blogger into a personal website? - javaAn open source tool for confusing HTTP POST requests - http-postExceptions Not Caught - debuggingUIWebview Resources for iPhone Download - iphoneUsing a separate version control system for changes when major version control is not available - version-controlImplement trace on i386 - cgroup_concat on an empty join in MySQL - joinRunning a VBA macro when a condition is met - vbaAll Articles