最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Addingpassing bootstrap class to the 'div' using javascript or jQuery - Stack Overflow

programmeradmin1浏览0评论

Folks!!

I am developing a website, in that showing the field errors in javascript alert()

User is not satisfy with the alert pop-up each time, and I thought to provide it in inline div block

I want to know how I can pass/add bootstrap class property{alert alert-warning} to the error block when I am passing Error Message from the javascript or jquery.

function getValidateField(){
  var varName= document.getElementById('txtNameSetting').value;
  if(varName.trim().length <= 0){
    //alert("Please enter Application Name");
    document.getElementById('divErrorBlock').innerHTML = "Please enter Application Name";
    document.getElementById('divErrorBlock').style.display = 'block';
    //$('#divErrorBlock').show(); 
    return false;
  }
  else return true;
}

If I pass inside the 'div', it will visible all the time, I need to hide this blcok until it get invoke

Thank in advance

Folks!!

I am developing a website, in that showing the field errors in javascript alert()

User is not satisfy with the alert pop-up each time, and I thought to provide it in inline div block

I want to know how I can pass/add bootstrap class property{alert alert-warning} to the error block when I am passing Error Message from the javascript or jquery.

function getValidateField(){
  var varName= document.getElementById('txtNameSetting').value;
  if(varName.trim().length <= 0){
    //alert("Please enter Application Name");
    document.getElementById('divErrorBlock').innerHTML = "Please enter Application Name";
    document.getElementById('divErrorBlock').style.display = 'block';
    //$('#divErrorBlock').show(); 
    return false;
  }
  else return true;
}

If I pass inside the 'div', it will visible all the time, I need to hide this blcok until it get invoke

Thank in advance

Share Improve this question asked Mar 24, 2016 at 5:09 Prajwal BhatPrajwal Bhat 3032 gold badges5 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Try setAttribute;

document.getElementById('divErrorBlock').setAttribute("class", "alert alert-warning");

or jquery addClass()

$('#divErrorBlock').addClass('alert alert-warning');

or using attr()

 $('#divErrorBlock').attr('class','alert alert-warning');

If you can use jquery. It is as simple as this.

$('#divErrorBlock').addClass('alert alert-warning');
发布评论

评论列表(0)

  1. 暂无评论