简体   繁体   中英

Jquery to add class in H1 tag in div

Trying to add class H1 tag inside div tag

function MatchReplace(content)
              {  
                  var input = content;
                  **$j('.wmd-preview').children().addClass('overridedefault');

 input = content.replace(/\<h1>/gi, "<h1 class='overridedefault'>");**
}

Tried both children() and add class but it's not added. please let me know if am missing something here

 $("#add").click(function(){ $('#adhere>h1').addClass("green") }) $( "#target" ).keyup(function() { $('#adhere>h1').addClass("green") }); 
 #adhere{ border: red 1px solid; } .green{ color:green; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div id="adhere"><h1>This is H1</h1></div> <button id='add'>add class</button> <input type="text" id="target" /> 

try this to add the class to the first H1 tag into div http://jsfiddle.net/mig1098/xd9ahwbw/

addingclass = function(_class){  
    $('.wmd-preview').find('h1').first().addClass(_class);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM