skip to Main Content

How can a wrap the content of an element with a <a> tag with the help of jQuery

I have following setup: <div class="vc_acf organisation"> <span class="vc_acf-label">Organisation:</span> CLEMI</div> </div> I want to change it in: <div class="vc_acf organisation"> <span class="vc_acf-label">Organisation:</span> <a href="https://beglobal.toc-web.site/resources/clemi">CLEMI</a></div> </div> What I got so far: (function($) { $(".organisation").each(function() { $(this).html($(this).html().replace(/CLEMI/g, "<a href='https://beglobal.toc-web.site/resources/clemi'>CLEMI</a>")); }); })(jQuery); This…

VIEW QUESTION

Jquery – Html select based on another select

Can someone help me correct this code. I need value attribute for some other purpose. I need the form to post both the category id and subcategory id. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> <script> $(document).ready(function(){ var $optgroups = $('#subcategory > optgroup'); $("#category").on("change",function(){ var…

VIEW QUESTION

Jquery – How to replace element's attr href with each

I want to change the href URL from the HTML string. But it prints the old URL instead of the test.php var html='<div><a href="https://www.spectrum.net/support/manage-account/creating-username?cid=eml_ehh_60_0621">find out how</a></div>'; $(html).find('a').each(function(){ var newUrl = "test.php"; $(this).attr("href", newUrl); }); console.log(html); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> OUTPUT: <div><a href="https://www.spectrum.net/support/manage-account/creating-username?cid=eml_ehh_60_0621">find…

VIEW QUESTION
Back To Top
Search