javascript - jQuery attribute Selectors Issue -


i have issue jquery attribute selector, can't understand why "div 1" got green background color in example.

$(document).ready(function() {    $('div[title],[style]').css('border', '5px solid red');    $('[title][style]').css('background-color', 'green');  })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <div title="div1title">    div 1  </div>  <p title="p1title">    paragraph 1  </p>  <div style="background-color:yellow">    div 2  </div>  <p title="p2title" style="background-color:yellow">    paragraph 2  </p>

because first line causes addition of style attribute div1, line

$('div[title],[style]').css('border', '5px solid red'); 

and div1 have title style attribute both , next line this

$('[title][style]').css('background-color', 'green'); 

applies it.

if don't want apply background color first div, switch order of lines